Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/unicode/stringtriebuilder.h
$ cat -n /usr/include/unicode/stringtriebuilder.h 1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ******************************************************************************* 5 * Copyright (C) 2010-2012,2014, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ******************************************************************************* 8 * file name: stringtriebuilder.h 9 * encoding: UTF-8 10 * tab size: 8 (not used) 11 * indentation:4 12 * 13 * created on: 2010dec24 14 * created by: Markus W. Scherer 15 */ 16 17 #ifndef __STRINGTRIEBUILDER_H__ 18 #define __STRINGTRIEBUILDER_H__ 19 20 #include "unicode/utypes.h" 21 22 #if U_SHOW_CPLUSPLUS_API 23 24 #include "unicode/uobject.h" 25 26 /** 27 * \file 28 * \brief C++ API: Builder API for trie builders 29 */ 30 31 // Forward declaration. 32 /// \cond 33 struct UHashtable; 34 typedef struct UHashtable UHashtable; 35 /// \endcond 36 37 /** 38 * Build options for BytesTrieBuilder and CharsTrieBuilder. 39 * @stable ICU 4.8 40 */ 41 enum UStringTrieBuildOption { 42 /** 43 * Builds a trie quickly. 44 * @stable ICU 4.8 45 */ 46 USTRINGTRIE_BUILD_FAST, 47 /** 48 * Builds a trie more slowly, attempting to generate 49 * a shorter but equivalent serialization. 50 * This build option also uses more memory. 51 * 52 * This option can be effective when many integer values are the same 53 * and string/byte sequence suffixes can be shared. 54 * Runtime speed is not expected to improve. 55 * @stable ICU 4.8 56 */ 57 USTRINGTRIE_BUILD_SMALL 58 }; 59 60 U_NAMESPACE_BEGIN 61 62 /** 63 * Base class for string trie builder classes. 64 * 65 * This class is not intended for public subclassing. 66 * @stable ICU 4.8 67 */ 68 class U_COMMON_API StringTrieBuilder : public UObject { 69 public: 70 #ifndef U_HIDE_INTERNAL_API 71 /** @internal */ 72 static int32_t hashNode(const void *node); 73 /** @internal */ 74 static UBool equalNodes(const void *left, const void *right); 75 #endif /* U_HIDE_INTERNAL_API */ 76 77 protected: 78 // Do not enclose the protected default constructor with #ifndef U_HIDE_INTERNAL_API 79 // or else the compiler will create a public default constructor. 80 /** @internal */ 81 StringTrieBuilder(); 82 /** @internal */ 83 virtual ~StringTrieBuilder(); 84 85 #ifndef U_HIDE_INTERNAL_API 86 /** @internal */ 87 void createCompactBuilder(int32_t sizeGuess, UErrorCode &errorCode); 88 /** @internal */ 89 void deleteCompactBuilder(); 90 91 /** @internal */ 92 void build(UStringTrieBuildOption buildOption, int32_t elementsLength, UErrorCode &errorCode); 93 94 /** @internal */ 95 int32_t writeNode(int32_t start, int32_t limit, int32_t unitIndex); 96 /** @internal */ 97 int32_t writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length); 98 #endif /* U_HIDE_INTERNAL_API */ 99 100 class Node; 101 102 #ifndef U_HIDE_INTERNAL_API 103 /** @internal */ 104 Node *makeNode(int32_t start, int32_t limit, int32_t unitIndex, UErrorCode &errorCode); 105 /** @internal */ 106 Node *makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, 107 int32_t length, UErrorCode &errorCode); 108 #endif /* U_HIDE_INTERNAL_API */ 109 110 /** @internal */ 111 virtual int32_t getElementStringLength(int32_t i) const = 0; 112 /** @internal */ 113 virtual char16_t getElementUnit(int32_t i, int32_t unitIndex) const = 0; 114 /** @internal */ 115 virtual int32_t getElementValue(int32_t i) const = 0; 116 117 // Finds the first unit index after this one where 118 // the first and last element have different units again. 119 /** @internal */ 120 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const = 0; 121 122 // Number of different units at unitIndex. 123 /** @internal */ 124 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const = 0; 125 /** @internal */ 126 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const = 0; 127 /** @internal */ 128 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const = 0; 129 130 /** @internal */ 131 virtual UBool matchNodesCanHaveValues() const = 0; 132 133 /** @internal */ 134 virtual int32_t getMaxBranchLinearSubNodeLength() const = 0; 135 /** @internal */ 136 virtual int32_t getMinLinearMatch() const = 0; 137 /** @internal */ 138 virtual int32_t getMaxLinearMatchLength() const = 0; 139 140 #ifndef U_HIDE_INTERNAL_API 141 // max(BytesTrie::kMaxBranchLinearSubNodeLength, UCharsTrie::kMaxBranchLinearSubNodeLength). 142 /** @internal */ 143 static const int32_t kMaxBranchLinearSubNodeLength=5; 144 145 // Maximum number of nested split-branch levels for a branch on all 2^16 possible char16_t units. 146 // log2(2^16/kMaxBranchLinearSubNodeLength) rounded up. 147 /** @internal */ 148 static const int32_t kMaxSplitBranchLevels=14; 149 150 /** 151 * Makes sure that there is only one unique node registered that is 152 * equivalent to newNode. 153 * @param newNode Input node. The builder takes ownership. 154 * @param errorCode ICU in/out UErrorCode. 155 Set to U_MEMORY_ALLOCATION_ERROR if it was success but newNode==nullptr. 156 * @return newNode if it is the first of its kind, or 157 * an equivalent node if newNode is a duplicate. 158 * @internal 159 */ 160 Node *registerNode(Node *newNode, UErrorCode &errorCode); 161 /** 162 * Makes sure that there is only one unique FinalValueNode registered 163 * with this value. 164 * Avoids creating a node if the value is a duplicate. 165 * @param value A final value. 166 * @param errorCode ICU in/out UErrorCode. 167 Set to U_MEMORY_ALLOCATION_ERROR if it was success but newNode==nullptr. 168 * @return A FinalValueNode with the given value. 169 * @internal 170 */ 171 Node *registerFinalValue(int32_t value, UErrorCode &errorCode); 172 #endif /* U_HIDE_INTERNAL_API */ 173 174 /* 175 * C++ note: 176 * registerNode() and registerFinalValue() take ownership of their input nodes, 177 * and only return owned nodes. 178 * If they see a failure UErrorCode, they will delete the input node. 179 * If they get a nullptr pointer, they will record a U_MEMORY_ALLOCATION_ERROR. 180 * If there is a failure, they return nullptr. 181 * 182 * nullptr Node pointers can be safely passed into other Nodes because 183 * they call the static Node::hashCode() which checks for a nullptr pointer first. 184 * 185 * Therefore, as long as builder functions register a new node, 186 * they need to check for failures only before explicitly dereferencing 187 * a Node pointer, or before setting a new UErrorCode. 188 */ 189 190 // Hash set of nodes, maps from nodes to integer 1. 191 /** @internal */ 192 UHashtable *nodes; 193 194 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, 195 // it is needed for layout of other objects. 196 /** 197 * @internal 198 * \cond 199 */ 200 class Node : public UObject { 201 public: 202 Node(int32_t initialHash) : hash(initialHash), offset(0) {} 203 inline int32_t hashCode() const { return hash; } 204 // Handles node==nullptr. 205 static inline int32_t hashCode(const Node *node) { return node==nullptr ? 0 : node->hashCode(); } 206 // Base class operator==() compares the actual class types. 207 virtual bool operator==(const Node &other) const; 208 inline bool operator!=(const Node &other) const { return !operator==(other); } 209 /** 210 * Traverses the Node graph and numbers branch edges, with rightmost edges first. 211 * This is to avoid writing a duplicate node twice. 212 * 213 * Branch nodes in this trie data structure are not symmetric. 214 * Most branch edges "jump" to other nodes but the rightmost branch edges 215 * just continue without a jump. 216 * Therefore, write() must write the rightmost branch edge last 217 * (trie units are written backwards), and must write it at that point even if 218 * it is a duplicate of a node previously written elsewhere. 219 * 220 * This function visits and marks right branch edges first. 221 * Edges are numbered with increasingly negative values because we share the 222 * offset field which gets positive values when nodes are written. 223 * A branch edge also remembers the first number for any of its edges. 224 * 225 * When a further-left branch edge has a number in the range of the rightmost 226 * edge's numbers, then it will be written as part of the required right edge 227 * and we can avoid writing it first. 228 * 229 * After root.markRightEdgesFirst(-1) the offsets of all nodes are negative 230 * edge numbers. 231 * 232 * @param edgeNumber The first edge number for this node and its sub-nodes. 233 * @return An edge number that is at least the maximum-negative 234 * of the input edge number and the numbers of this node and all of its sub-nodes. 235 */ 236 virtual int32_t markRightEdgesFirst(int32_t edgeNumber); 237 // write() must set the offset to a positive value. 238 virtual void write(StringTrieBuilder &builder) = 0; 239 // See markRightEdgesFirst. 240 inline void writeUnlessInsideRightEdge(int32_t firstRight, int32_t lastRight, 241 StringTrieBuilder &builder) { 242 // Note: Edge numbers are negative, lastRight<=firstRight. 243 // If offset>0 then this node and its sub-nodes have been written already 244 // and we need not write them again. 245 // If this node is part of the unwritten right branch edge, 246 // then we wait until that is written. 247 if(offset<0 && (offset
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™