15 #ifndef __STRINGTRIEBUILDER_H__
16 #define __STRINGTRIEBUILDER_H__
23 typedef struct UHashtable UHashtable;
29 enum UStringTrieBuildOption {
34 USTRINGTRIE_BUILD_FAST,
45 USTRINGTRIE_BUILD_SMALL
59 static UBool hashNode(
const void *node);
61 static UBool equalNodes(
const void *left,
const void *right);
70 void createCompactBuilder(int32_t sizeGuess,
UErrorCode &errorCode);
72 void deleteCompactBuilder();
75 void build(UStringTrieBuildOption buildOption, int32_t elementsLength,
UErrorCode &errorCode);
78 int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex);
80 int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length);
85 Node *makeNode(int32_t start, int32_t limit, int32_t unitIndex,
UErrorCode &errorCode);
87 Node *makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex,
91 virtual int32_t getElementStringLength(int32_t i)
const = 0;
93 virtual UChar getElementUnit(int32_t i, int32_t unitIndex)
const = 0;
95 virtual int32_t getElementValue(int32_t i)
const = 0;
100 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex)
const = 0;
104 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex)
const = 0;
106 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count)
const = 0;
108 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex,
UChar unit)
const = 0;
111 virtual UBool matchNodesCanHaveValues()
const = 0;
114 virtual int32_t getMaxBranchLinearSubNodeLength()
const = 0;
116 virtual int32_t getMinLinearMatch()
const = 0;
118 virtual int32_t getMaxLinearMatchLength()
const = 0;
122 static const int32_t kMaxBranchLinearSubNodeLength=5;
127 static const int32_t kMaxSplitBranchLevels=14;
175 Node(int32_t initialHash) : hash(initialHash), offset(0) {}
176 inline int32_t hashCode()
const {
return hash; }
178 static inline int32_t hashCode(
const Node *node) {
return node==
NULL ? 0 : node->hashCode(); }
209 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
213 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
220 if(offset<0 && (offset<lastRight || firstRight<offset)) {
224 inline int32_t getOffset()
const {
return offset; }
230 virtual UClassID getDynamicClassID()
const;
254 void setValue(int32_t v) {
268 :
ValueNode(0x222222*37+hashCode(nextNode)), next(nextNode) { setValue(v); }
270 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
280 :
ValueNode((0x333333*37+len)*37+hashCode(nextNode)),
281 length(len), next(nextNode) {}
283 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
294 int32_t firstEdgeNumber;
302 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
305 void add(int32_t c, int32_t value) {
306 units[length]=(
UChar)c;
308 values[length]=value;
310 hash=(hash*37+c)*37+value;
313 void add(int32_t c,
Node *node) {
314 units[length]=(
UChar)c;
318 hash=(hash*37+c)*37+hashCode(node);
321 Node *equal[kMaxBranchLinearSubNodeLength];
323 int32_t values[kMaxBranchLinearSubNodeLength];
324 UChar units[kMaxBranchLinearSubNodeLength];
332 hashCode(lessThanNode))*37+hashCode(greaterOrEqualNode)),
333 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
335 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
340 Node *greaterOrEqual;
348 :
ValueNode((0x666666*37+len)*37+hashCode(subNode)),
349 length(len), next(subNode) {}
351 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
359 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
360 Node *nextNode)
const = 0;
363 virtual int32_t write(int32_t unit) = 0;
365 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) = 0;
367 virtual int32_t writeValueAndFinal(int32_t i,
UBool isFinal) = 0;
369 virtual int32_t writeValueAndType(
UBool hasValue, int32_t value, int32_t node) = 0;
371 virtual int32_t writeDeltaTo(int32_t jumpTarget) = 0;
380 #endif // __STRINGTRIEBUILDER_H__