15 #ifndef __STRINGTRIEBUILDER_H__
16 #define __STRINGTRIEBUILDER_H__
28 typedef struct UHashtable UHashtable;
63 #ifndef U_HIDE_INTERNAL_API
65 static UBool hashNode(
const void *node);
67 static UBool equalNodes(
const void *left,
const void *right);
78 #ifndef U_HIDE_INTERNAL_API
80 void createCompactBuilder(int32_t sizeGuess,
UErrorCode &errorCode);
82 void deleteCompactBuilder();
88 int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex);
90 int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length);
95 #ifndef U_HIDE_INTERNAL_API
97 Node *makeNode(int32_t start, int32_t limit, int32_t unitIndex,
UErrorCode &errorCode);
99 Node *makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex,
104 virtual int32_t getElementStringLength(int32_t i)
const = 0;
106 virtual UChar getElementUnit(int32_t i, int32_t unitIndex)
const = 0;
108 virtual int32_t getElementValue(int32_t i)
const = 0;
113 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex)
const = 0;
117 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex)
const = 0;
119 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count)
const = 0;
121 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex,
UChar unit)
const = 0;
124 virtual UBool matchNodesCanHaveValues()
const = 0;
127 virtual int32_t getMaxBranchLinearSubNodeLength()
const = 0;
129 virtual int32_t getMinLinearMatch()
const = 0;
131 virtual int32_t getMaxLinearMatchLength()
const = 0;
133 #ifndef U_HIDE_INTERNAL_API
136 static const int32_t kMaxBranchLinearSubNodeLength=5;
141 static const int32_t kMaxSplitBranchLevels=14;
189 Node(int32_t initialHash) : hash(initialHash), offset(0) {}
190 inline int32_t hashCode()
const {
return hash; }
192 static inline int32_t hashCode(
const Node *node) {
return node==
NULL ? 0 : node->hashCode(); }
223 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
227 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
234 if(offset<0 && (offset<lastRight || firstRight<offset)) {
238 inline int32_t getOffset()
const {
return offset; }
244 virtual UClassID getDynamicClassID()
const;
270 void setValue(int32_t v) {
286 :
ValueNode(0x222222*37+hashCode(nextNode)), next(nextNode) { setValue(v); }
288 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
300 :
ValueNode((0x333333*37+len)*37+hashCode(nextNode)),
301 length(len), next(nextNode) {}
303 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
316 int32_t firstEdgeNumber;
326 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
329 void add(int32_t c, int32_t value) {
330 units[length]=(
UChar)c;
332 values[length]=value;
334 hash=(hash*37+c)*37+value;
337 void add(int32_t c,
Node *node) {
338 units[length]=(
UChar)c;
342 hash=(hash*37+c)*37+hashCode(node);
345 Node *equal[kMaxBranchLinearSubNodeLength];
347 int32_t values[kMaxBranchLinearSubNodeLength];
348 UChar units[kMaxBranchLinearSubNodeLength];
358 hashCode(lessThanNode))*37+hashCode(greaterOrEqualNode)),
359 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
361 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
366 Node *greaterOrEqual;
374 :
ValueNode((0x666666*37+len)*37+hashCode(subNode)),
375 length(len), next(subNode) {}
377 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
386 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
387 Node *nextNode)
const = 0;
390 virtual int32_t write(int32_t unit) = 0;
392 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) = 0;
394 virtual int32_t writeValueAndFinal(int32_t i,
UBool isFinal) = 0;
396 virtual int32_t writeValueAndType(
UBool hasValue, int32_t value, int32_t node) = 0;
398 virtual int32_t writeDeltaTo(int32_t jumpTarget) = 0;
407 #endif // __STRINGTRIEBUILDER_H__
Builds a trie more slowly, attempting to generate a shorter but equivalent serialization.
Base class for string trie builder classes.
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
#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 0 for C++ and to ((void *)0) for C.
#define TRUE
The TRUE value of a UBool.
C++ API: Common ICU base class UObject.
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
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.