17#ifndef __STRINGTRIEBUILDER_H__
18#define __STRINGTRIEBUILDER_H__
22#if U_SHOW_CPLUSPLUS_API
70#ifndef U_HIDE_INTERNAL_API
85#ifndef U_HIDE_INTERNAL_API
102#ifndef U_HIDE_INTERNAL_API
146#ifndef U_HIDE_INTERNAL_API
149 static const int32_t kMaxBranchLinearSubNodeLength=5;
154 static const int32_t kMaxSplitBranchLevels=14;
209 inline int32_t hashCode()
const {
return hash; }
257 inline int32_t getOffset()
const {
return offset; }
263#ifndef U_HIDE_INTERNAL_API
274 virtual bool operator==(
const Node &other)
const override;
275 virtual void write(StringTrieBuilder &builder)
override;
286 class ValueNode :
public Node {
288 ValueNode(int32_t initialHash) : Node(initialHash), hasValue(false), value(0) {}
289 virtual bool operator==(
const Node &other)
const override;
290 void setValue(int32_t v) {
300#ifndef U_HIDE_INTERNAL_API
304 class IntermediateValueNode :
public ValueNode {
306 IntermediateValueNode(int32_t v, Node *nextNode)
307 : ValueNode(0x222222u*37u+hashCode(nextNode)), next(nextNode) { setValue(v); }
308 virtual bool operator==(
const Node &other)
const override;
309 virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
override;
310 virtual void write(StringTrieBuilder &builder)
override;
321 class LinearMatchNode :
public ValueNode {
323 LinearMatchNode(int32_t len, Node *nextNode)
324 : ValueNode((0x333333u*37u+len)*37u+hashCode(nextNode)),
325 length(len), next(nextNode) {}
326 virtual bool operator==(
const Node &other)
const override;
327 virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
override;
333#ifndef U_HIDE_INTERNAL_API
337 class BranchNode :
public Node {
339 BranchNode(int32_t initialHash) : Node(initialHash) {}
341 int32_t firstEdgeNumber;
347 class ListBranchNode :
public BranchNode {
349 ListBranchNode() : BranchNode(0x444444), length(0) {}
350 virtual bool operator==(
const Node &other)
const override;
351 virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
override;
352 virtual void write(StringTrieBuilder &builder)
override;
354 void add(int32_t c, int32_t value) {
355 units[length] =
static_cast<char16_t>(c);
356 equal[length]=
nullptr;
357 values[length]=value;
359 hash=(hash*37u+c)*37u+value;
362 void add(int32_t c, Node *node) {
363 units[length] =
static_cast<char16_t>(c);
367 hash=(hash*37u+c)*37u+hashCode(node);
370 Node *equal[kMaxBranchLinearSubNodeLength];
372 int32_t values[kMaxBranchLinearSubNodeLength];
373 char16_t units[kMaxBranchLinearSubNodeLength];
379 class SplitBranchNode :
public BranchNode {
381 SplitBranchNode(
char16_t middleUnit, Node *lessThanNode, Node *greaterOrEqualNode)
382 : BranchNode(((0x555555u*37u+middleUnit)*37u+
383 hashCode(lessThanNode))*37u+hashCode(greaterOrEqualNode)),
384 unit(middleUnit), lessThan(lessThanNode), greaterOrEqual(greaterOrEqualNode) {}
385 virtual bool operator==(
const Node &other)
const override;
386 virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
override;
387 virtual void write(StringTrieBuilder &builder)
override;
391 Node *greaterOrEqual;
396 class BranchHeadNode :
public ValueNode {
398 BranchHeadNode(int32_t len, Node *subNode)
399 : ValueNode((0x666666u*37u+len)*37u+hashCode(subNode)),
400 length(len), next(subNode) {}
401 virtual bool operator==(
const Node &other)
const override;
402 virtual int32_t markRightEdgesFirst(int32_t edgeNumber)
override;
403 virtual void write(StringTrieBuilder &builder)
override;
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Base class for string trie builder classes.
static UBool equalNodes(const void *left, const void *right)
static int32_t hashNode(const void *node)
virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal)=0
virtual int32_t getMaxBranchLinearSubNodeLength() const =0
Node * registerFinalValue(int32_t value, UErrorCode &errorCode)
Makes sure that there is only one unique FinalValueNode registered with this value.
virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const =0
virtual ~StringTrieBuilder()
virtual int32_t writeDeltaTo(int32_t jumpTarget)=0
Node * registerNode(Node *newNode, UErrorCode &errorCode)
Makes sure that there is only one unique node registered that is equivalent to newNode.
int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex)
Node * makeNode(int32_t start, int32_t limit, int32_t unitIndex, UErrorCode &errorCode)
virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const =0
Node * makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length, UErrorCode &errorCode)
int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length)
virtual int32_t getElementValue(int32_t i) const =0
void deleteCompactBuilder()
virtual int32_t getMinLinearMatch() const =0
virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const =0
void build(UStringTrieBuildOption buildOption, int32_t elementsLength, UErrorCode &errorCode)
virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node)=0
virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const =0
virtual UBool matchNodesCanHaveValues() const =0
virtual int32_t write(int32_t unit)=0
virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const =0
virtual Node * createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length, Node *nextNode) const =0
virtual int32_t getMaxLinearMatchLength() const =0
virtual int32_t getElementStringLength(int32_t i) const =0
void createCompactBuilder(int32_t sizeGuess, UErrorCode &errorCode)
virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length)=0
UObject is the common ICU "boilerplate" class.
struct UHashtable UHashtable
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
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, a signed-byte integer.
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.