15#ifndef __STRINGTRIEBUILDER_H__
16#define __STRINGTRIEBUILDER_H__
63#ifndef U_HIDE_INTERNAL_API
78#ifndef U_HIDE_INTERNAL_API
88 int32_t
writeNode(int32_t start, int32_t limit, int32_t unitIndex);
95#ifndef U_HIDE_INTERNAL_API
133#ifndef U_HIDE_INTERNAL_API
187#ifndef U_HIDE_INTERNAL_API
191 Node(int32_t initialHash) : hash(initialHash), offset(0) {}
192 inline int32_t hashCode()
const {
return hash; }
194 static inline int32_t hashCode(
const Node *node) {
return node==
NULL ? 0 : node->hashCode(); }
229 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
236 if(offset<0 && (offset<lastRight || firstRight<offset)) {
240 inline int32_t getOffset()
const {
return offset; }
253 class FinalValueNode :
public Node {
255 FinalValueNode(int32_t v) : Node(0x111111*37+v), value(v) {}
265 class ValueNode :
public Node {
267 ValueNode(int32_t initialHash) : Node(initialHash), hasValue(
FALSE), value(0) {}
269 void setValue(int32_t v) {
282 class IntermediateValueNode :
public ValueNode {
284 IntermediateValueNode(int32_t v,
Node *nextNode)
285 : ValueNode(0x222222*37+hashCode(nextNode)), next(nextNode) { setValue(v); }
296 class LinearMatchNode :
public ValueNode {
298 LinearMatchNode(int32_t len,
Node *nextNode)
299 : ValueNode((0x333333*37+len)*37+hashCode(nextNode)),
300 length(len), next(nextNode) {}
311 class BranchNode :
public Node {
313 BranchNode(int32_t initialHash) : Node(initialHash) {}
315 int32_t firstEdgeNumber;
321 class ListBranchNode :
public BranchNode {
323 ListBranchNode() : BranchNode(0x444444), length(0) {}
328 void add(int32_t c, int32_t value) {
329 units[length]=(
UChar)c;
331 values[length]=value;
333 hash=(hash*37+c)*37+value;
336 void add(int32_t c,
Node *node) {
337 units[length]=(
UChar)c;
341 hash=(hash*37+c)*37+hashCode(node);
344 Node *equal[kMaxBranchLinearSubNodeLength];
346 int32_t values[kMaxBranchLinearSubNodeLength];
347 UChar units[kMaxBranchLinearSubNodeLength];
353 class SplitBranchNode :
public BranchNode {
355 SplitBranchNode(
UChar middleUnit,
Node *lessThanNode,
Node *greaterOrEqualNode)
356 : BranchNode(((0x555555*37+middleUnit)*37+
357 hashCode(lessThanNode))*37+hashCode(greaterOrEqualNode)),
358 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
365 Node *greaterOrEqual;
370 class BranchHeadNode :
public ValueNode {
372 BranchHeadNode(int32_t len,
Node *subNode)
373 : ValueNode((0x666666*37+len)*37+hashCode(subNode)),
374 length(len), next(subNode) {}
386 Node *nextNode)
const = 0;
389 virtual int32_t
write(int32_t unit) = 0;
virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
Traverses the Node graph and numbers branch edges, with rightmost edges first.
virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
Traverses the Node graph and numbers branch edges, with rightmost edges first.
virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
Traverses the Node graph and numbers branch edges, with rightmost edges first.
virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
Traverses the Node graph and numbers branch edges, with rightmost edges first.
virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
Traverses the Node graph and numbers branch edges, with rightmost edges first.
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const =0
static UBool equalNodes(const void *left, const void *right)
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const =0
virtual int32_t getMaxBranchLinearSubNodeLength() const =0
static const int32_t kMaxBranchLinearSubNodeLength
Node * makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length, UErrorCode &errorCode)
static UBool hashNode(const void *node)
virtual int32_t write(int32_t unit)=0
static const int32_t kMaxSplitBranchLevels
void createCompactBuilder(int32_t sizeGuess, UErrorCode &errorCode)
virtual Node * createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length, Node *nextNode) const =0
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const =0
virtual int32_t getMinLinearMatch() const =0
virtual int32_t getElementValue(int32_t i) const =0
virtual int32_t getElementStringLength(int32_t i) const =0
virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const =0
Node * registerFinalValue(int32_t value, UErrorCode &errorCode)
Makes sure that there is only one unique FinalValueNode registered with this value.
virtual UBool matchNodesCanHaveValues() const =0
virtual ~StringTrieBuilder()
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal)=0
int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex)
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const =0
int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length)
virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length)=0
void deleteCompactBuilder()
virtual int32_t writeDeltaTo(int32_t jumpTarget)=0
void build(UStringTrieBuildOption buildOption, int32_t elementsLength, UErrorCode &errorCode)
Node * makeNode(int32_t start, int32_t limit, int32_t unitIndex, UErrorCode &errorCode)
virtual int32_t getMaxLinearMatchLength() const =0
Node * registerNode(Node *newNode, UErrorCode &errorCode)
Makes sure that there is only one unique node registered that is equivalent to newNode.
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node)=0
UObject is the common ICU "boilerplate" class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
struct UHashtable UHashtable
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
@ USTRINGTRIE_BUILD_SMALL
Builds a trie more slowly, attempting to generate a shorter but equivalent serialization.
@ USTRINGTRIE_BUILD_FAST
Builds a trie quickly.
int8_t UBool
The ICU boolean type.
#define TRUE
The TRUE value of a UBool.
#define FALSE
The FALSE value of a UBool.
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.