ucharstrie.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. *******************************************************************************
  8. * file name: ucharstrie.h
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 2010nov14
  14. * created by: Markus W. Scherer
  15. */
  16. #ifndef __UCHARSTRIE_H__
  17. #define __UCHARSTRIE_H__
  18. /**
  19. * \file
  20. * \brief C++ API: Trie for mapping Unicode strings (or 16-bit-unit sequences)
  21. * to integer values.
  22. */
  23. #include "unicode/utypes.h"
  24. #if U_SHOW_CPLUSPLUS_API
  25. #include "unicode/unistr.h"
  26. #include "unicode/uobject.h"
  27. #include "unicode/ustringtrie.h"
  28. U_NAMESPACE_BEGIN
  29. class Appendable;
  30. class UCharsTrieBuilder;
  31. class UVector32;
  32. /**
  33. * Light-weight, non-const reader class for a UCharsTrie.
  34. * Traverses a char16_t-serialized data structure with minimal state,
  35. * for mapping strings (16-bit-unit sequences) to non-negative integer values.
  36. *
  37. * This class owns the serialized trie data only if it was constructed by
  38. * the builder's build() method.
  39. * The public constructor and the copy constructor only alias the data (only copy the pointer).
  40. * There is no assignment operator.
  41. *
  42. * This class is not intended for public subclassing.
  43. * @stable ICU 4.8
  44. */
  45. class U_COMMON_API UCharsTrie : public UMemory {
  46. public:
  47. /**
  48. * Constructs a UCharsTrie reader instance.
  49. *
  50. * The trieUChars must contain a copy of a char16_t sequence from the UCharsTrieBuilder,
  51. * starting with the first char16_t of that sequence.
  52. * The UCharsTrie object will not read more char16_ts than
  53. * the UCharsTrieBuilder generated in the corresponding build() call.
  54. *
  55. * The array is not copied/cloned and must not be modified while
  56. * the UCharsTrie object is in use.
  57. *
  58. * @param trieUChars The char16_t array that contains the serialized trie.
  59. * @stable ICU 4.8
  60. */
  61. UCharsTrie(ConstChar16Ptr trieUChars)
  62. : ownedArray_(NULL), uchars_(trieUChars),
  63. pos_(uchars_), remainingMatchLength_(-1) {}
  64. /**
  65. * Destructor.
  66. * @stable ICU 4.8
  67. */
  68. ~UCharsTrie();
  69. /**
  70. * Copy constructor, copies the other trie reader object and its state,
  71. * but not the char16_t array which will be shared. (Shallow copy.)
  72. * @param other Another UCharsTrie object.
  73. * @stable ICU 4.8
  74. */
  75. UCharsTrie(const UCharsTrie &other)
  76. : ownedArray_(NULL), uchars_(other.uchars_),
  77. pos_(other.pos_), remainingMatchLength_(other.remainingMatchLength_) {}
  78. /**
  79. * Resets this trie to its initial state.
  80. * @return *this
  81. * @stable ICU 4.8
  82. */
  83. UCharsTrie &reset() {
  84. pos_=uchars_;
  85. remainingMatchLength_=-1;
  86. return *this;
  87. }
  88. #ifndef U_HIDE_DRAFT_API
  89. /**
  90. * Returns the state of this trie as a 64-bit integer.
  91. * The state value is never 0.
  92. *
  93. * @return opaque state value
  94. * @see resetToState64
  95. * @draft ICU 65
  96. */
  97. uint64_t getState64() const {
  98. return (static_cast<uint64_t>(remainingMatchLength_ + 2) << kState64RemainingShift) |
  99. (uint64_t)(pos_ - uchars_);
  100. }
  101. /**
  102. * Resets this trie to the saved state.
  103. * Unlike resetToState(State), the 64-bit state value
  104. * must be from getState64() from the same trie object or
  105. * from one initialized the exact same way.
  106. * Because of no validation, this method is faster.
  107. *
  108. * @param state The opaque trie state value from getState64().
  109. * @return *this
  110. * @see getState64
  111. * @see resetToState
  112. * @see reset
  113. * @draft ICU 65
  114. */
  115. UCharsTrie &resetToState64(uint64_t state) {
  116. remainingMatchLength_ = static_cast<int32_t>(state >> kState64RemainingShift) - 2;
  117. pos_ = uchars_ + (state & kState64PosMask);
  118. return *this;
  119. }
  120. #endif /* U_HIDE_DRAFT_API */
  121. /**
  122. * UCharsTrie state object, for saving a trie's current state
  123. * and resetting the trie back to this state later.
  124. * @stable ICU 4.8
  125. */
  126. class State : public UMemory {
  127. public:
  128. /**
  129. * Constructs an empty State.
  130. * @stable ICU 4.8
  131. */
  132. State() { uchars=NULL; }
  133. private:
  134. friend class UCharsTrie;
  135. const char16_t *uchars;
  136. const char16_t *pos;
  137. int32_t remainingMatchLength;
  138. };
  139. /**
  140. * Saves the state of this trie.
  141. * @param state The State object to hold the trie's state.
  142. * @return *this
  143. * @see resetToState
  144. * @stable ICU 4.8
  145. */
  146. const UCharsTrie &saveState(State &state) const {
  147. state.uchars=uchars_;
  148. state.pos=pos_;
  149. state.remainingMatchLength=remainingMatchLength_;
  150. return *this;
  151. }
  152. /**
  153. * Resets this trie to the saved state.
  154. * If the state object contains no state, or the state of a different trie,
  155. * then this trie remains unchanged.
  156. * @param state The State object which holds a saved trie state.
  157. * @return *this
  158. * @see saveState
  159. * @see reset
  160. * @stable ICU 4.8
  161. */
  162. UCharsTrie &resetToState(const State &state) {
  163. if(uchars_==state.uchars && uchars_!=NULL) {
  164. pos_=state.pos;
  165. remainingMatchLength_=state.remainingMatchLength;
  166. }
  167. return *this;
  168. }
  169. /**
  170. * Determines whether the string so far matches, whether it has a value,
  171. * and whether another input char16_t can continue a matching string.
  172. * @return The match/value Result.
  173. * @stable ICU 4.8
  174. */
  175. UStringTrieResult current() const;
  176. /**
  177. * Traverses the trie from the initial state for this input char16_t.
  178. * Equivalent to reset().next(uchar).
  179. * @param uchar Input char value. Values below 0 and above 0xffff will never match.
  180. * @return The match/value Result.
  181. * @stable ICU 4.8
  182. */
  183. inline UStringTrieResult first(int32_t uchar) {
  184. remainingMatchLength_=-1;
  185. return nextImpl(uchars_, uchar);
  186. }
  187. /**
  188. * Traverses the trie from the initial state for the
  189. * one or two UTF-16 code units for this input code point.
  190. * Equivalent to reset().nextForCodePoint(cp).
  191. * @param cp A Unicode code point 0..0x10ffff.
  192. * @return The match/value Result.
  193. * @stable ICU 4.8
  194. */
  195. UStringTrieResult firstForCodePoint(UChar32 cp);
  196. /**
  197. * Traverses the trie from the current state for this input char16_t.
  198. * @param uchar Input char value. Values below 0 and above 0xffff will never match.
  199. * @return The match/value Result.
  200. * @stable ICU 4.8
  201. */
  202. UStringTrieResult next(int32_t uchar);
  203. /**
  204. * Traverses the trie from the current state for the
  205. * one or two UTF-16 code units for this input code point.
  206. * @param cp A Unicode code point 0..0x10ffff.
  207. * @return The match/value Result.
  208. * @stable ICU 4.8
  209. */
  210. UStringTrieResult nextForCodePoint(UChar32 cp);
  211. /**
  212. * Traverses the trie from the current state for this string.
  213. * Equivalent to
  214. * \code
  215. * Result result=current();
  216. * for(each c in s)
  217. * if(!USTRINGTRIE_HAS_NEXT(result)) return USTRINGTRIE_NO_MATCH;
  218. * result=next(c);
  219. * return result;
  220. * \endcode
  221. * @param s A string. Can be NULL if length is 0.
  222. * @param length The length of the string. Can be -1 if NUL-terminated.
  223. * @return The match/value Result.
  224. * @stable ICU 4.8
  225. */
  226. UStringTrieResult next(ConstChar16Ptr s, int32_t length);
  227. /**
  228. * Returns a matching string's value if called immediately after
  229. * current()/first()/next() returned USTRINGTRIE_INTERMEDIATE_VALUE or USTRINGTRIE_FINAL_VALUE.
  230. * getValue() can be called multiple times.
  231. *
  232. * Do not call getValue() after USTRINGTRIE_NO_MATCH or USTRINGTRIE_NO_VALUE!
  233. * @return The value for the string so far.
  234. * @stable ICU 4.8
  235. */
  236. inline int32_t getValue() const {
  237. const char16_t *pos=pos_;
  238. int32_t leadUnit=*pos++;
  239. // U_ASSERT(leadUnit>=kMinValueLead);
  240. return leadUnit&kValueIsFinal ?
  241. readValue(pos, leadUnit&0x7fff) : readNodeValue(pos, leadUnit);
  242. }
  243. /**
  244. * Determines whether all strings reachable from the current state
  245. * map to the same value.
  246. * @param uniqueValue Receives the unique value, if this function returns TRUE.
  247. * (output-only)
  248. * @return TRUE if all strings reachable from the current state
  249. * map to the same value.
  250. * @stable ICU 4.8
  251. */
  252. inline UBool hasUniqueValue(int32_t &uniqueValue) const {
  253. const char16_t *pos=pos_;
  254. // Skip the rest of a pending linear-match node.
  255. return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, FALSE, uniqueValue);
  256. }
  257. /**
  258. * Finds each char16_t which continues the string from the current state.
  259. * That is, each char16_t c for which it would be next(c)!=USTRINGTRIE_NO_MATCH now.
  260. * @param out Each next char16_t is appended to this object.
  261. * @return the number of char16_ts which continue the string from here
  262. * @stable ICU 4.8
  263. */
  264. int32_t getNextUChars(Appendable &out) const;
  265. /**
  266. * Iterator for all of the (string, value) pairs in a UCharsTrie.
  267. * @stable ICU 4.8
  268. */
  269. class U_COMMON_API Iterator : public UMemory {
  270. public:
  271. /**
  272. * Iterates from the root of a char16_t-serialized UCharsTrie.
  273. * @param trieUChars The trie char16_ts.
  274. * @param maxStringLength If 0, the iterator returns full strings.
  275. * Otherwise, the iterator returns strings with this maximum length.
  276. * @param errorCode Standard ICU error code. Its input value must
  277. * pass the U_SUCCESS() test, or else the function returns
  278. * immediately. Check for U_FAILURE() on output or use with
  279. * function chaining. (See User Guide for details.)
  280. * @stable ICU 4.8
  281. */
  282. Iterator(ConstChar16Ptr trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
  283. /**
  284. * Iterates from the current state of the specified UCharsTrie.
  285. * @param trie The trie whose state will be copied for iteration.
  286. * @param maxStringLength If 0, the iterator returns full strings.
  287. * Otherwise, the iterator returns strings with this maximum length.
  288. * @param errorCode Standard ICU error code. Its input value must
  289. * pass the U_SUCCESS() test, or else the function returns
  290. * immediately. Check for U_FAILURE() on output or use with
  291. * function chaining. (See User Guide for details.)
  292. * @stable ICU 4.8
  293. */
  294. Iterator(const UCharsTrie &trie, int32_t maxStringLength, UErrorCode &errorCode);
  295. /**
  296. * Destructor.
  297. * @stable ICU 4.8
  298. */
  299. ~Iterator();
  300. /**
  301. * Resets this iterator to its initial state.
  302. * @return *this
  303. * @stable ICU 4.8
  304. */
  305. Iterator &reset();
  306. /**
  307. * @return TRUE if there are more elements.
  308. * @stable ICU 4.8
  309. */
  310. UBool hasNext() const;
  311. /**
  312. * Finds the next (string, value) pair if there is one.
  313. *
  314. * If the string is truncated to the maximum length and does not
  315. * have a real value, then the value is set to -1.
  316. * In this case, this "not a real value" is indistinguishable from
  317. * a real value of -1.
  318. * @param errorCode Standard ICU error code. Its input value must
  319. * pass the U_SUCCESS() test, or else the function returns
  320. * immediately. Check for U_FAILURE() on output or use with
  321. * function chaining. (See User Guide for details.)
  322. * @return TRUE if there is another element.
  323. * @stable ICU 4.8
  324. */
  325. UBool next(UErrorCode &errorCode);
  326. /**
  327. * @return The string for the last successful next().
  328. * @stable ICU 4.8
  329. */
  330. const UnicodeString &getString() const { return str_; }
  331. /**
  332. * @return The value for the last successful next().
  333. * @stable ICU 4.8
  334. */
  335. int32_t getValue() const { return value_; }
  336. private:
  337. UBool truncateAndStop() {
  338. pos_=NULL;
  339. value_=-1; // no real value for str
  340. return TRUE;
  341. }
  342. const char16_t *branchNext(const char16_t *pos, int32_t length, UErrorCode &errorCode);
  343. const char16_t *uchars_;
  344. const char16_t *pos_;
  345. const char16_t *initialPos_;
  346. int32_t remainingMatchLength_;
  347. int32_t initialRemainingMatchLength_;
  348. UBool skipValue_; // Skip intermediate value which was already delivered.
  349. UnicodeString str_;
  350. int32_t maxLength_;
  351. int32_t value_;
  352. // The stack stores pairs of integers for backtracking to another
  353. // outbound edge of a branch node.
  354. // The first integer is an offset from uchars_.
  355. // The second integer has the str_.length() from before the node in bits 15..0,
  356. // and the remaining branch length in bits 31..16.
  357. // (We could store the remaining branch length minus 1 in bits 30..16 and not use the sign bit,
  358. // but the code looks more confusing that way.)
  359. UVector32 *stack_;
  360. };
  361. private:
  362. friend class UCharsTrieBuilder;
  363. /**
  364. * Constructs a UCharsTrie reader instance.
  365. * Unlike the public constructor which just aliases an array,
  366. * this constructor adopts the builder's array.
  367. * This constructor is only called by the builder.
  368. */
  369. UCharsTrie(char16_t *adoptUChars, const char16_t *trieUChars)
  370. : ownedArray_(adoptUChars), uchars_(trieUChars),
  371. pos_(uchars_), remainingMatchLength_(-1) {}
  372. // No assignment operator.
  373. UCharsTrie &operator=(const UCharsTrie &other);
  374. inline void stop() {
  375. pos_=NULL;
  376. }
  377. // Reads a compact 32-bit integer.
  378. // pos is already after the leadUnit, and the lead unit has bit 15 reset.
  379. static inline int32_t readValue(const char16_t *pos, int32_t leadUnit) {
  380. int32_t value;
  381. if(leadUnit<kMinTwoUnitValueLead) {
  382. value=leadUnit;
  383. } else if(leadUnit<kThreeUnitValueLead) {
  384. value=((leadUnit-kMinTwoUnitValueLead)<<16)|*pos;
  385. } else {
  386. value=(pos[0]<<16)|pos[1];
  387. }
  388. return value;
  389. }
  390. static inline const char16_t *skipValue(const char16_t *pos, int32_t leadUnit) {
  391. if(leadUnit>=kMinTwoUnitValueLead) {
  392. if(leadUnit<kThreeUnitValueLead) {
  393. ++pos;
  394. } else {
  395. pos+=2;
  396. }
  397. }
  398. return pos;
  399. }
  400. static inline const char16_t *skipValue(const char16_t *pos) {
  401. int32_t leadUnit=*pos++;
  402. return skipValue(pos, leadUnit&0x7fff);
  403. }
  404. static inline int32_t readNodeValue(const char16_t *pos, int32_t leadUnit) {
  405. // U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
  406. int32_t value;
  407. if(leadUnit<kMinTwoUnitNodeValueLead) {
  408. value=(leadUnit>>6)-1;
  409. } else if(leadUnit<kThreeUnitNodeValueLead) {
  410. value=(((leadUnit&0x7fc0)-kMinTwoUnitNodeValueLead)<<10)|*pos;
  411. } else {
  412. value=(pos[0]<<16)|pos[1];
  413. }
  414. return value;
  415. }
  416. static inline const char16_t *skipNodeValue(const char16_t *pos, int32_t leadUnit) {
  417. // U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
  418. if(leadUnit>=kMinTwoUnitNodeValueLead) {
  419. if(leadUnit<kThreeUnitNodeValueLead) {
  420. ++pos;
  421. } else {
  422. pos+=2;
  423. }
  424. }
  425. return pos;
  426. }
  427. static inline const char16_t *jumpByDelta(const char16_t *pos) {
  428. int32_t delta=*pos++;
  429. if(delta>=kMinTwoUnitDeltaLead) {
  430. if(delta==kThreeUnitDeltaLead) {
  431. delta=(pos[0]<<16)|pos[1];
  432. pos+=2;
  433. } else {
  434. delta=((delta-kMinTwoUnitDeltaLead)<<16)|*pos++;
  435. }
  436. }
  437. return pos+delta;
  438. }
  439. static const char16_t *skipDelta(const char16_t *pos) {
  440. int32_t delta=*pos++;
  441. if(delta>=kMinTwoUnitDeltaLead) {
  442. if(delta==kThreeUnitDeltaLead) {
  443. pos+=2;
  444. } else {
  445. ++pos;
  446. }
  447. }
  448. return pos;
  449. }
  450. static inline UStringTrieResult valueResult(int32_t node) {
  451. return (UStringTrieResult)(USTRINGTRIE_INTERMEDIATE_VALUE-(node>>15));
  452. }
  453. // Handles a branch node for both next(uchar) and next(string).
  454. UStringTrieResult branchNext(const char16_t *pos, int32_t length, int32_t uchar);
  455. // Requires remainingLength_<0.
  456. UStringTrieResult nextImpl(const char16_t *pos, int32_t uchar);
  457. // Helper functions for hasUniqueValue().
  458. // Recursively finds a unique value (or whether there is not a unique one)
  459. // from a branch.
  460. static const char16_t *findUniqueValueFromBranch(const char16_t *pos, int32_t length,
  461. UBool haveUniqueValue, int32_t &uniqueValue);
  462. // Recursively finds a unique value (or whether there is not a unique one)
  463. // starting from a position on a node lead unit.
  464. static UBool findUniqueValue(const char16_t *pos, UBool haveUniqueValue, int32_t &uniqueValue);
  465. // Helper functions for getNextUChars().
  466. // getNextUChars() when pos is on a branch node.
  467. static void getNextBranchUChars(const char16_t *pos, int32_t length, Appendable &out);
  468. // UCharsTrie data structure
  469. //
  470. // The trie consists of a series of char16_t-serialized nodes for incremental
  471. // Unicode string/char16_t sequence matching. (char16_t=16-bit unsigned integer)
  472. // The root node is at the beginning of the trie data.
  473. //
  474. // Types of nodes are distinguished by their node lead unit ranges.
  475. // After each node, except a final-value node, another node follows to
  476. // encode match values or continue matching further units.
  477. //
  478. // Node types:
  479. // - Final-value node: Stores a 32-bit integer in a compact, variable-length format.
  480. // The value is for the string/char16_t sequence so far.
  481. // - Match node, optionally with an intermediate value in a different compact format.
  482. // The value, if present, is for the string/char16_t sequence so far.
  483. //
  484. // Aside from the value, which uses the node lead unit's high bits:
  485. //
  486. // - Linear-match node: Matches a number of units.
  487. // - Branch node: Branches to other nodes according to the current input unit.
  488. // The node unit is the length of the branch (number of units to select from)
  489. // minus 1. It is followed by a sub-node:
  490. // - If the length is at most kMaxBranchLinearSubNodeLength, then
  491. // there are length-1 (key, value) pairs and then one more comparison unit.
  492. // If one of the key units matches, then the value is either a final value for
  493. // the string so far, or a "jump" delta to the next node.
  494. // If the last unit matches, then matching continues with the next node.
  495. // (Values have the same encoding as final-value nodes.)
  496. // - If the length is greater than kMaxBranchLinearSubNodeLength, then
  497. // there is one unit and one "jump" delta.
  498. // If the input unit is less than the sub-node unit, then "jump" by delta to
  499. // the next sub-node which will have a length of length/2.
  500. // (The delta has its own compact encoding.)
  501. // Otherwise, skip the "jump" delta to the next sub-node
  502. // which will have a length of length-length/2.
  503. // Match-node lead unit values, after masking off intermediate-value bits:
  504. // 0000..002f: Branch node. If node!=0 then the length is node+1, otherwise
  505. // the length is one more than the next unit.
  506. // For a branch sub-node with at most this many entries, we drop down
  507. // to a linear search.
  508. static const int32_t kMaxBranchLinearSubNodeLength=5;
  509. // 0030..003f: Linear-match node, match 1..16 units and continue reading the next node.
  510. static const int32_t kMinLinearMatch=0x30;
  511. static const int32_t kMaxLinearMatchLength=0x10;
  512. // Match-node lead unit bits 14..6 for the optional intermediate value.
  513. // If these bits are 0, then there is no intermediate value.
  514. // Otherwise, see the *NodeValue* constants below.
  515. static const int32_t kMinValueLead=kMinLinearMatch+kMaxLinearMatchLength; // 0x0040
  516. static const int32_t kNodeTypeMask=kMinValueLead-1; // 0x003f
  517. // A final-value node has bit 15 set.
  518. static const int32_t kValueIsFinal=0x8000;
  519. // Compact value: After testing and masking off bit 15, use the following thresholds.
  520. static const int32_t kMaxOneUnitValue=0x3fff;
  521. static const int32_t kMinTwoUnitValueLead=kMaxOneUnitValue+1; // 0x4000
  522. static const int32_t kThreeUnitValueLead=0x7fff;
  523. static const int32_t kMaxTwoUnitValue=((kThreeUnitValueLead-kMinTwoUnitValueLead)<<16)-1; // 0x3ffeffff
  524. // Compact intermediate-value integer, lead unit shared with a branch or linear-match node.
  525. static const int32_t kMaxOneUnitNodeValue=0xff;
  526. static const int32_t kMinTwoUnitNodeValueLead=kMinValueLead+((kMaxOneUnitNodeValue+1)<<6); // 0x4040
  527. static const int32_t kThreeUnitNodeValueLead=0x7fc0;
  528. static const int32_t kMaxTwoUnitNodeValue=
  529. ((kThreeUnitNodeValueLead-kMinTwoUnitNodeValueLead)<<10)-1; // 0xfdffff
  530. // Compact delta integers.
  531. static const int32_t kMaxOneUnitDelta=0xfbff;
  532. static const int32_t kMinTwoUnitDeltaLead=kMaxOneUnitDelta+1; // 0xfc00
  533. static const int32_t kThreeUnitDeltaLead=0xffff;
  534. static const int32_t kMaxTwoUnitDelta=((kThreeUnitDeltaLead-kMinTwoUnitDeltaLead)<<16)-1; // 0x03feffff
  535. // For getState64():
  536. // The remainingMatchLength_ is -1..14=(kMaxLinearMatchLength=0x10)-2
  537. // so we need at least 5 bits for that.
  538. // We add 2 to store it as a positive value 1..16=kMaxLinearMatchLength.
  539. static constexpr int32_t kState64RemainingShift = 59;
  540. static constexpr uint64_t kState64PosMask = (UINT64_C(1) << kState64RemainingShift) - 1;
  541. char16_t *ownedArray_;
  542. // Fixed value referencing the UCharsTrie words.
  543. const char16_t *uchars_;
  544. // Iterator variables.
  545. // Pointer to next trie unit to read. NULL if no more matches.
  546. const char16_t *pos_;
  547. // Remaining length of a linear-match node, minus 1. Negative if not in such a node.
  548. int32_t remainingMatchLength_;
  549. };
  550. U_NAMESPACE_END
  551. #endif /* U_SHOW_CPLUSPLUS_API */
  552. #endif // __UCHARSTRIE_H__