|
6 | 6 | * |
7 | 7 | * ========================================================================== |
8 | 8 | * "Compressed String Dictionaries" |
9 | | - * Nieves R. Brisaboa, Rodrigo Canovas, Francisco Claude, |
| 9 | + * Nieves R. Brisaboa, Rodrigo Canovas, Francisco Claude, |
10 | 10 | * Miguel A. Martinez-Prieto and Gonzalo Navarro. |
11 | 11 | * 10th Symposium on Experimental Algorithms (SEA'2011), p.136-147, 2011. |
12 | 12 | * ========================================================================== |
|
34 | 34 | #ifndef _COMPRESSEDSTRINGDICTIONARY_H |
35 | 35 | #define _COMPRESSEDSTRINGDICTIONARY_H |
36 | 36 |
|
37 | | -#include <stdint.h> |
38 | 37 | #include <Iterator.hpp> |
39 | | -#include <iostream> |
40 | 38 | #include <cassert> |
| 39 | +#include <iostream> |
| 40 | +#include <stdint.h> |
41 | 41 | #include <vector> |
42 | 42 | using namespace std; |
43 | 43 |
|
44 | | -namespace csd |
45 | | -{ |
| 44 | +namespace csd { |
46 | 45 | static const uint32_t PFC = 2; |
47 | 46 | static const uint32_t HTFC = 3; |
48 | 47 | static const uint32_t FMINDEX = 4; |
49 | 48 | static const uint32_t REPAIRDAC = 5; |
50 | 49 | static const uint32_t HASHHUFF = 6; |
51 | 50 |
|
52 | | -class CSD |
53 | | -{ |
54 | | - public: |
55 | | - CSD(); |
56 | | - /** General destructor */ |
57 | | - virtual ~CSD() {}; |
| 51 | +class CSD { |
| 52 | +public: |
| 53 | + CSD(); |
| 54 | + /** General destructor */ |
| 55 | + virtual ~CSD(){}; |
| 56 | + |
| 57 | + /** Returns the ID that identify s[1..length]. If it does not exist, |
| 58 | + returns 0. |
| 59 | + @s: the string to be located. |
| 60 | + @len: the length (in characters) of the string s. |
| 61 | + */ |
| 62 | + virtual size_t locate(const unsigned char *s, size_t len) = 0; |
58 | 63 |
|
59 | | - /** Returns the ID that identify s[1..length]. If it does not exist, |
60 | | - returns 0. |
61 | | - @s: the string to be located. |
62 | | - @len: the length (in characters) of the string s. |
63 | | - */ |
64 | | - virtual size_t locate(const unsigned char *s, size_t len)=0; |
| 64 | + /** Returns the string identified by id. |
| 65 | + @id: the identifier to be extracted. |
| 66 | + */ |
| 67 | + virtual unsigned char *extract(size_t id) = 0; |
65 | 68 |
|
66 | | - /** Returns the string identified by id. |
67 | | - @id: the identifier to be extracted. |
68 | | - */ |
69 | | - virtual unsigned char * extract(size_t id)=0; |
| 69 | + /** |
| 70 | + * Free the string returned by extract() |
| 71 | + */ |
| 72 | + virtual void freeString(const unsigned char *) = 0; |
70 | 73 |
|
71 | | - /** |
72 | | - * Free the string returned by extract() |
73 | | - */ |
74 | | - virtual void freeString(const unsigned char *)=0; |
| 74 | + /** Returns the size of the structure in bytes. */ |
| 75 | + virtual uint64_t getSize() = 0; |
75 | 76 |
|
76 | | - /** Returns the size of the structure in bytes. */ |
77 | | - virtual uint64_t getSize()=0; |
| 77 | + virtual hdt::IteratorUCharString *listAll() = 0; |
78 | 78 |
|
79 | | - virtual hdt::IteratorUCharString *listAll()=0; |
| 79 | + /** Returns the number of strings in the dictionary. */ |
| 80 | + size_t getLength(); |
80 | 81 |
|
81 | | - /** Returns the number of strings in the dictionary. */ |
82 | | - size_t getLength(); |
| 82 | + // Search for terms by prefix. It returns a vector of a given maximum size |
| 83 | + // "maxResults" |
| 84 | + virtual void fillSuggestions(const char *prefix, vector<string> &out, |
| 85 | + int maxResults) = 0; |
83 | 86 |
|
84 | | - // Search for terms by prefix. It returns a vector of a given maximum size "maxResults" |
85 | | - virtual void fillSuggestions(const char *prefix, vector<string> &out, int maxResults)=0; |
| 87 | + // Search for terms by prefix. It returns an iterator of all results in the |
| 88 | + // dictionary |
| 89 | + virtual hdt::IteratorUCharString *getSuggestions(const char *prefix) = 0; |
86 | 90 |
|
87 | | - // Search for terms by prefix. It returns an iterator of all results in the dictionary |
88 | | - virtual hdt::IteratorUCharString *getSuggestions(const char *prefix)=0; |
| 91 | + // Search for terms by prefix. It returns an iterator of all results in the |
| 92 | + // dictionary, by ID |
| 93 | + virtual hdt::IteratorUInt *getIDSuggestions(const char *prefix) = 0; |
89 | 94 |
|
90 | | - // Search for terms by prefix. It returns an iterator of all results in the dictionary, by ID |
91 | | - virtual hdt::IteratorUInt *getIDSuggestions(const char *prefix)=0; |
| 95 | + /** Stores a CSD structure given a file pointer. |
| 96 | + @fp: pointer to the file saving a CSD structure. |
| 97 | + */ |
| 98 | + virtual void save(ostream &fp) = 0; |
92 | 99 |
|
93 | | - /** Stores a CSD structure given a file pointer. |
94 | | - @fp: pointer to the file saving a CSD structure. |
95 | | - */ |
96 | | - virtual void save(ostream & fp)=0; |
| 100 | + virtual size_t load(unsigned char *ptr, unsigned char *ptrMax) = 0; |
97 | 101 |
|
98 | | - virtual size_t load(unsigned char *ptr, unsigned char *ptrMax)=0; |
| 102 | + /** Loads a CSD structure from a file pointer. |
| 103 | + @fp: pointer to the file storing a CSD structure. */ |
| 104 | + static CSD *load(istream &fp); |
99 | 105 |
|
100 | | - /** Loads a CSD structure from a file pointer. |
101 | | - @fp: pointer to the file storing a CSD structure. */ |
102 | | - static CSD * load(istream & fp); |
| 106 | + static CSD *create(unsigned char type); |
103 | 107 |
|
104 | | - static CSD * create(unsigned char type); |
105 | | - |
106 | | - protected: |
107 | | - unsigned char type; //! Dictionary type. |
108 | | - size_t tlength; //! Original Tdict size. |
109 | | - size_t numstrings; //! Number of elements in the dictionary. |
110 | | - }; |
| 108 | +protected: |
| 109 | + unsigned char type; //! Dictionary type. |
| 110 | + size_t tlength; //! Original Tdict size. |
| 111 | + size_t numstrings; //! Number of elements in the dictionary. |
| 112 | +}; |
111 | 113 |
|
112 | | -} |
| 114 | +} // namespace csd |
113 | 115 |
|
114 | | -#endif |
| 116 | +#endif |
0 commit comments