15 #ifndef __STRINGTRIEBUILDER_H__
16 #define __STRINGTRIEBUILDER_H__
23 typedef struct UHashtable UHashtable;
29 enum UStringTrieBuildOption {
34 USTRINGTRIE_BUILD_FAST,
45 USTRINGTRIE_BUILD_SMALL
58 #ifndef U_HIDE_INTERNAL_API
60 static UBool hashNode(
const void *node);
62 static UBool equalNodes(
const void *left,
const void *right);
73 #ifndef U_HIDE_INTERNAL_API
75 void createCompactBuilder(int32_t sizeGuess,
UErrorCode &errorCode);
77 void deleteCompactBuilder();
80 void build(UStringTrieBuildOption buildOption, int32_t elementsLength,
UErrorCode &errorCode);
83 int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex);
85 int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length);
90 #ifndef U_HIDE_INTERNAL_API
92 Node *makeNode(int32_t start, int32_t limit, int32_t unitIndex,
UErrorCode &errorCode);
94 Node *makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex,
99 virtual int32_t getElementStringLength(int32_t i)
const = 0;
101 virtual UChar getElementUnit(int32_t i, int32_t unitIndex)
const = 0;
103 virtual int32_t getElementValue(int32_t i)
const = 0;
108 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex)
const = 0;
112 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex)
const = 0;
114 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count)
const = 0;
116 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex,
UChar unit)
const = 0;
119 virtual UBool matchNodesCanHaveValues()
const = 0;
122 virtual int32_t getMaxBranchLinearSubNodeLength()
const = 0;
124 virtual int32_t getMinLinearMatch()
const = 0;
126 virtual int32_t getMaxLinearMatchLength()
const = 0;
128 #ifndef U_HIDE_INTERNAL_API
131 static const int32_t kMaxBranchLinearSubNodeLength=5;
136 static const int32_t kMaxSplitBranchLevels=14;
184 Node(int32_t initialHash) : hash(initialHash), offset(0) {}
185 inline int32_t hashCode()
const {
return hash; }
187 static inline int32_t hashCode(
const Node *node) {
return node==
NULL ? 0 : node->hashCode(); }
218 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
222 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
229 if(offset<0 && (offset<lastRight || firstRight<offset)) {
233 inline int32_t getOffset()
const {
return offset; }
239 virtual UClassID getDynamicClassID()
const;
263 void setValue(int32_t v) {
277 :
ValueNode(0x222222*37+hashCode(nextNode)), next(nextNode) { setValue(v); }
279 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
289 :
ValueNode((0x333333*37+len)*37+hashCode(nextNode)),
290 length(len), next(nextNode) {}
292 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
303 int32_t firstEdgeNumber;
311 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
314 void add(int32_t c, int32_t value) {
315 units[length]=(
UChar)c;
317 values[length]=value;
319 hash=(hash*37+c)*37+value;
322 void add(int32_t c,
Node *node) {
323 units[length]=(
UChar)c;
327 hash=(hash*37+c)*37+hashCode(node);
330 Node *equal[kMaxBranchLinearSubNodeLength];
332 int32_t values[kMaxBranchLinearSubNodeLength];
333 UChar units[kMaxBranchLinearSubNodeLength];
341 hashCode(lessThanNode))*37+hashCode(greaterOrEqualNode)),
342 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
344 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
349 Node *greaterOrEqual;
357 :
ValueNode((0x666666*37+len)*37+hashCode(subNode)),
358 length(len), next(subNode) {}
360 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
369 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
370 Node *nextNode)
const = 0;
373 virtual int32_t write(int32_t unit) = 0;
375 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) = 0;
377 virtual int32_t writeValueAndFinal(int32_t i,
UBool isFinal) = 0;
379 virtual int32_t writeValueAndType(
UBool hasValue, int32_t value, int32_t node) = 0;
381 virtual int32_t writeDeltaTo(int32_t jumpTarget) = 0;
390 #endif // __STRINGTRIEBUILDER_H__