17 #ifndef __STRINGTRIEBUILDER_H__ 18 #define __STRINGTRIEBUILDER_H__ 67 #ifndef U_HIDE_INTERNAL_API 69 static int32_t hashNode(
const void *node);
71 static UBool equalNodes(
const void *left,
const void *right);
80 virtual ~StringTrieBuilder();
82 #ifndef U_HIDE_INTERNAL_API 84 void createCompactBuilder(int32_t sizeGuess,
UErrorCode &errorCode);
86 void deleteCompactBuilder();
92 int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex);
94 int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length);
99 #ifndef U_HIDE_INTERNAL_API 101 Node *makeNode(int32_t start, int32_t limit, int32_t unitIndex,
UErrorCode &errorCode);
103 Node *makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex,
108 virtual int32_t getElementStringLength(int32_t i)
const = 0;
110 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex)
const = 0;
112 virtual int32_t getElementValue(int32_t i)
const = 0;
117 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex)
const = 0;
121 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex)
const = 0;
123 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count)
const = 0;
125 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit)
const = 0;
128 virtual UBool matchNodesCanHaveValues()
const = 0;
131 virtual int32_t getMaxBranchLinearSubNodeLength()
const = 0;
133 virtual int32_t getMinLinearMatch()
const = 0;
135 virtual int32_t getMaxLinearMatchLength()
const = 0;
137 #ifndef U_HIDE_INTERNAL_API 140 static const int32_t kMaxBranchLinearSubNodeLength=5;
145 static const int32_t kMaxSplitBranchLevels=14;
157 Node *registerNode(Node *newNode,
UErrorCode &errorCode);
168 Node *registerFinalValue(int32_t value,
UErrorCode &errorCode);
197 class Node :
public UObject {
199 Node(int32_t initialHash) : hash(initialHash), offset(0) {}
200 inline int32_t hashCode()
const {
return hash; }
202 static inline int32_t hashCode(
const Node *node) {
return node==
NULL ? 0 : node->hashCode(); }
233 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
235 virtual void write(StringTrieBuilder &builder) = 0;
237 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
238 StringTrieBuilder &builder) {
244 if(offset<0 && (offset<lastRight || firstRight<offset)) {
248 inline int32_t getOffset()
const {
return offset; }
254 #ifndef U_HIDE_INTERNAL_API 262 class FinalValueNode :
public Node {
264 FinalValueNode(int32_t v) : Node(0x111111u*37u+v), value(v) {}
266 virtual void write(StringTrieBuilder &builder);
277 class ValueNode :
public Node {
279 ValueNode(int32_t initialHash) : Node(initialHash), hasValue(
FALSE), value(0) {}
281 void setValue(int32_t v) {
291 #ifndef U_HIDE_INTERNAL_API 295 class IntermediateValueNode :
public ValueNode {
297 IntermediateValueNode(int32_t v, Node *nextNode)
298 : ValueNode(0x222222u*37u+hashCode(nextNode)), next(nextNode) { setValue(v); }
300 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
301 virtual void write(StringTrieBuilder &builder);
312 class LinearMatchNode :
public ValueNode {
314 LinearMatchNode(int32_t len, Node *nextNode)
315 : ValueNode((0x333333u*37u+len)*37u+hashCode(nextNode)),
316 length(len), next(nextNode) {}
318 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
324 #ifndef U_HIDE_INTERNAL_API 328 class BranchNode :
public Node {
330 BranchNode(int32_t initialHash) : Node(initialHash) {}
332 int32_t firstEdgeNumber;
338 class ListBranchNode :
public BranchNode {
340 ListBranchNode() : BranchNode(0x444444), length(0) {}
342 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
343 virtual void write(StringTrieBuilder &builder);
345 void add(int32_t c, int32_t value) {
346 units[length]=(char16_t)c;
348 values[length]=value;
350 hash=(hash*37u+c)*37u+value;
353 void add(int32_t c, Node *node) {
354 units[length]=(char16_t)c;
358 hash=(hash*37u+c)*37u+hashCode(node);
361 Node *equal[kMaxBranchLinearSubNodeLength];
363 int32_t values[kMaxBranchLinearSubNodeLength];
364 char16_t units[kMaxBranchLinearSubNodeLength];
370 class SplitBranchNode :
public BranchNode {
372 SplitBranchNode(char16_t middleUnit, Node *lessThanNode, Node *greaterOrEqualNode)
373 : BranchNode(((0x555555u*37u+middleUnit)*37u+
374 hashCode(lessThanNode))*37u+hashCode(greaterOrEqualNode)),
375 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
377 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
378 virtual void write(StringTrieBuilder &builder);
382 Node *greaterOrEqual;
387 class BranchHeadNode :
public ValueNode {
389 BranchHeadNode(int32_t len, Node *subNode)
390 : ValueNode((0x666666u*37u+len)*37u+hashCode(subNode)),
391 length(len), next(subNode) {}
393 virtual int32_t markRightEdgesFirst(int32_t edgeNumber);
394 virtual void write(StringTrieBuilder &builder);
404 virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
405 Node *nextNode)
const = 0;
408 virtual int32_t write(int32_t unit) = 0;
410 virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length) = 0;
412 virtual int32_t writeValueAndFinal(int32_t i,
UBool isFinal) = 0;
414 virtual int32_t writeValueAndType(
UBool hasValue, int32_t value, int32_t node) = 0;
416 virtual int32_t writeDeltaTo(int32_t jumpTarget) = 0;
421 #endif // __STRINGTRIEBUILDER_H__ struct UHashtable UHashtable
Builds a trie more slowly, attempting to generate a shorter but equivalent serialization.
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...
int8_t UBool
The ICU boolean type.