protected: // Do not enclose the protected default constructor with #ifndef U_HIDE_INTERNAL_API // or else the compiler will create a public default constructor. /** @internal */
StringTrieBuilder(); /** @internal */ virtual ~StringTrieBuilder();
// Finds the first unit index after this one where // the first and last element have different units again. /** @internal */ virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const = 0;
// Number of different units at unitIndex. /** @internal */ virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const= 0; /** @internal */ virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const = 0; /** @internal */ virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const = 0;
// Maximum number of nested split-branch levels for a branch on all 2^16 possible char16_t units. // log2(2^16/kMaxBranchLinearSubNodeLength) rounded up. /** @internal */ staticconst int32_t kMaxSplitBranchLevels=14;
// Hash set of nodes, maps from nodes to integer 1. /** @internal */
UHashtable *nodes;
// Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, // it is needed for layout of other objects. /** *@internal *\cond
*/ class Node : public UObject { public:
Node(int32_t initialHash) : hash(initialHash), offset(0) {}
inline int32_t hashCode() const { return hash; } // Handles node==nullptr. static inline int32_t hashCode(const Node *node) { return node==nullptr ? 0 : node->hashCode(); } // Base class operator==() compares the actual class types. virtualbooloperator==(const Node &other) const;
inline booloperator!=(const Node &other) const { return !operator==(other); } /** *TraversestheNodegraphandnumbersbranchedges,withrightmostedgesfirst. *Thisistoavoidwritingaduplicatenodetwice. * *Branchnodesinthistriedatastructurearenotsymmetric. *Mostbranchedges"jump"toothernodesbuttherightmostbranchedges *justcontinuewithoutajump. *Therefore,write()mustwritetherightmostbranchedgelast *(trieunitsarewrittenbackwards),andmustwriteitatthatpointevenif *itisaduplicateofanodepreviouslywrittenelsewhere. * *Thisfunctionvisitsandmarksrightbranchedgesfirst. *Edgesarenumberedwithincreasinglynegativevaluesbecausewesharethe *offsetfieldwhichgetspositivevalueswhennodesarewritten. *Abranchedgealsoremembersthefirstnumberforanyofitsedges. * *Whenafurther-leftbranchedgehasanumberintherangeoftherightmost *edge'snumbers,thenitwillbewrittenaspartoftherequiredrightedge *andwecanavoidwritingitfirst. * *Afterroot.markRightEdgesFirst(-1)theoffsetsofallnodesarenegative *edgenumbers. * *@paramedgeNumberThefirstedgenumberforthisnodeanditssub-nodes. *@returnAnedgenumberthatisatleastthemaximum-negative *oftheinputedgenumberandthenumbersofthisnodeandallofitssub-nodes.
*/ virtual int32_t markRightEdgesFirst(int32_t edgeNumber); // write() must set the offset to a positive value. virtualvoid write(StringTrieBuilder &builder) = 0; // See markRightEdgesFirst.
inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight,
StringTrieBuilder &builder) { // Note: Edge numbers are negative, lastRight<=firstRight. // If offset>0 then this node and its sub-nodes have been written already // and we need not write them again. // If this node is part of the unwritten right branch edge, // then we wait until that is written.
if(offset<0 && (offset<lastRight || firstRight<offset)) {
write(builder);
}
}
inline int32_t getOffset() const { return offset; } protected:
int32_t hash;
int32_t offset;
};
#ifndef U_HIDE_INTERNAL_API // This class should not be overridden because // registerFinalValue() compares a stack-allocated FinalValueNode // (stack-allocated so that we don't unnecessarily create lots of duplicate nodes) // with the input node, and the // !Node::operator==(other) used inside FinalValueNode::operator==(other) // will be false if the typeid's are different. /** @internal */ class FinalValueNode : public Node { public:
FinalValueNode(int32_t v) : Node(0x111111u*37u+v), value(v) {} virtualbooloperator==(const Node &other) const override; virtualvoid write(StringTrieBuilder &builder) override; protected:
int32_t value;
}; #endif/* U_HIDE_INTERNAL_API */
// Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, // it is needed for layout of other objects. /** *@internal
*/ class ValueNode : public Node { public:
ValueNode(int32_t initialHash) : Node(initialHash), hasValue(false), value(0) {} virtualbooloperator==(const Node &other) const override; void setValue(int32_t v) {
hasValue=true;
value=v;
hash=hash*37u+v;
} protected:
UBool hasValue;
int32_t value;
};
// Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, // it is needed for layout of other objects. /** *@internal
*/ class LinearMatchNode : public ValueNode { public:
LinearMatchNode(int32_t len, Node *nextNode)
: ValueNode((0x333333u*37u+len)*37u+hashCode(nextNode)),
length(len), next(nextNode) {} virtualbooloperator==(const Node &other) const override; virtual int32_t markRightEdgesFirst(int32_t edgeNumber) override; protected:
int32_t length;
Node *next;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.