ucharstrie.h 23 KB

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