17 #ifndef __STRINGTRIEBUILDER_H__ 18 #define __STRINGTRIEBUILDER_H__ 30 typedef struct UHashtable UHashtable;
65 #ifndef U_HIDE_INTERNAL_API 67 static UBool hashNode(
const void *node);
69 static UBool equalNodes(
const void *left,
const void *right);
80 #ifndef U_HIDE_INTERNAL_API 82 void createCompactBuilder(int32_t sizeGuess,
UErrorCode &errorCode);
84 void deleteCompactBuilder();
90 int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex);
92 int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length);
97 #ifndef U_HIDE_INTERNAL_API 99 Node *makeNode(int32_t start, int32_t limit, int32_t unitIndex,
UErrorCode &errorCode);
101 Node *makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex,
106 virtual int32_t getElementStringLength(int32_t i)
const = 0;
108 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex)
const = 0;
110 virtual int32_t getElementValue(int32_t i)
const = 0;
115 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex)
const = 0;
119 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex)
const = 0;
121 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count)
const = 0;
123 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit)
const = 0;
126 virtual UBool matchNodesCanHaveValues()
const = 0;
129 virtual int32_t getMaxBranchLinearSubNodeLength()
const = 0;
131 virtual int32_t getMinLinearMatch()
const = 0;
133 virtual int32_t getMaxLinearMatchLength()
const = 0;
135 #ifndef U_HIDE_INTERNAL_API 138 static const int32_t kMaxBranchLinearSubNodeLength=5;
143 static const int32_t kMaxSplitBranchLevels=14;
194 Node(int32_t initialHash) : hash(initialHash), offset(0) {}
195 inline int32_t hashCode()
const {
return hash; }
197 static inline int32_t hashCode(
const Node *node) {
return node==
NULL ? 0 : node->hashCode(); }
228 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
232 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
239 if(offset<0 && (offset<lastRight || firstRight<offset)) {
243 inline int32_t getOffset()
const {
return offset; }
249 #ifndef U_HIDE_INTERNAL_API 276 void setValue(int32_t v) {
286 #ifndef U_HIDE_INTERNAL_API 293 :
ValueNode(0x222222u*37u+hashCode(nextNode)), next(nextNode) { setValue(v); }
295 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
310 :
ValueNode((0x333333u*37u+len)*37u+hashCode(nextNode)),
311 length(len), next(nextNode) {}
313 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
319 #ifndef U_HIDE_INTERNAL_API 327 int32_t firstEdgeNumber;
337 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
340 void add(int32_t c, int32_t value) {
341 units[length]=(char16_t)c;
343 values[length]=value;
345 hash=(hash*37u+c)*37u+value;
348 void add(int32_t c,
Node *node) {
349 units[length]=(char16_t)c;
353 hash=(hash*37u+c)*37u+hashCode(node);
356 Node *equal[kMaxBranchLinearSubNodeLength];
358 int32_t values[kMaxBranchLinearSubNodeLength];
359 char16_t units[kMaxBranchLinearSubNodeLength];
369 hashCode(lessThanNode))*37u+hashCode(greaterOrEqualNode)),
370 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
372 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
377 Node *greaterOrEqual;
385 :
ValueNode((0x666666u*37u+len)*37u+hashCode(subNode)),
386 length(len), next(subNode) {}
388 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
397 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
398 Node *nextNode)
const = 0;
401 virtual int32_t write(int32_t unit) = 0;
403 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) = 0;
405 virtual int32_t writeValueAndFinal(int32_t i,
UBool isFinal) = 0;
407 virtual int32_t writeValueAndType(
UBool hasValue, int32_t value, int32_t node) = 0;
409 virtual int32_t writeDeltaTo(int32_t jumpTarget) = 0;
414 #endif // __STRINGTRIEBUILDER_H__
Builds a trie more slowly, attempting to generate a shorter but equivalent serialization.
Base class for string trie builder classes.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
#define TRUE
The TRUE value of a UBool.
C++ API: Common ICU base class UObject.
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Basic definitions for ICU, for both C and C++ APIs.
#define FALSE
The FALSE value of a UBool.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
UObject is the common ICU "boilerplate" class.
int8_t UBool
The ICU boolean type.