00001
00038 #ifndef __PrefixGraph__
00039 #define __PrefixGraph__
00040
00041
00042 #include "PrefixNodeBase.h"
00043
00044
00059 class PrefixGraph {
00060 public:
00061
00062 typedef uint64_t Head;
00063 typedef uint32_t DataIndex;
00064 typedef uint32_t Data;
00065
00066 private:
00067
00068
00069 struct Node : public PrefixNodeBase<Head> {
00070
00071 inline DataIndex& getDataIndex(Head encoded_letter) {
00072 return sufix[ countLetters(encoded_letter) ];
00073 }
00074
00075 DataIndex sufix[0];
00076 };
00077
00078 protected:
00079
00081 long size;
00082
00084 Head* codes;
00085
00099 Data* data;
00100
00101 private:
00102
00103 bool has(const char *str, Node* node);
00104 bool has(const char *str, Node* node, unsigned int &match);
00105
00106 public:
00107
00108 PrefixGraph() {
00109 size = 0;
00110 codes = NULL;
00111 data = NULL;
00112 }
00113
00114 ~PrefixGraph() {
00115 delete[] codes;
00116 delete[] data;
00117 codes = NULL;
00118 data = NULL;
00119 }
00120
00126 inline bool has(const char *word) {
00127 return has(word, (Node*)data);
00128 }
00129
00139 inline bool has(const char *word, unsigned int &match) {
00140 return has(word, (Node*)data, match);
00141 }
00142
00152 int build(const char *filename);
00153
00157 void save(const char* filename);
00158
00164 void load(const char* filename);
00165 };
00166
00167 #endif