17 #ifndef __BYTESTRIE_H__
18 #define __BYTESTRIE_H__
27 #if U_SHOW_CPLUSPLUS_API
36 class BytesTrieBuilder;
70 : ownedArray_(
NULL), bytes_(static_cast<const uint8_t *>(trieBytes)),
71 pos_(bytes_), remainingMatchLength_(-1) {}
86 : ownedArray_(
NULL), bytes_(other.bytes_),
87 pos_(other.pos_), remainingMatchLength_(other.remainingMatchLength_) {}
96 remainingMatchLength_=-1;
100 #ifndef U_HIDE_DRAFT_API
110 return (static_cast<uint64_t>(remainingMatchLength_ + 2) << kState64RemainingShift) |
111 (uint64_t)(pos_ - bytes_);
129 remainingMatchLength_ = static_cast<int32_t>(state >> kState64RemainingShift) - 2;
130 pos_ = bytes_ + (state & kState64PosMask);
150 const uint8_t *bytes;
152 int32_t remainingMatchLength;
165 state.remainingMatchLength=remainingMatchLength_;
180 if(bytes_==state.bytes && bytes_!=
NULL) {
182 remainingMatchLength_=state.remainingMatchLength;
204 remainingMatchLength_=-1;
208 return nextImpl(bytes_, inByte);
247 const uint8_t *pos=pos_;
248 int32_t leadByte=*pos++;
250 return readValue(pos, leadByte>>1);
263 const uint8_t *pos=pos_;
265 return pos!=
NULL && findUniqueValue(pos+remainingMatchLength_+1,
FALSE, uniqueValue);
276 int32_t getNextBytes(
ByteSink &out)
const;
327 UBool hasNext()
const;
357 UBool truncateAndStop();
359 const uint8_t *branchNext(
const uint8_t *pos, int32_t length,
UErrorCode &errorCode);
361 const uint8_t *bytes_;
363 const uint8_t *initialPos_;
364 int32_t remainingMatchLength_;
365 int32_t initialRemainingMatchLength_;
390 BytesTrie(
void *adoptBytes,
const void *trieBytes)
391 : ownedArray_(static_cast<uint8_t *>(adoptBytes)),
392 bytes_(static_cast<const uint8_t *>(trieBytes)),
393 pos_(bytes_), remainingMatchLength_(-1) {}
396 BytesTrie &operator=(
const BytesTrie &other);
404 static int32_t readValue(
const uint8_t *pos, int32_t leadByte);
405 static inline const uint8_t *skipValue(
const uint8_t *pos, int32_t leadByte) {
407 if(leadByte>=(kMinTwoByteValueLead<<1)) {
408 if(leadByte<(kMinThreeByteValueLead<<1)) {
410 }
else if(leadByte<(kFourByteValueLead<<1)) {
413 pos+=3+((leadByte>>1)&1);
418 static inline const uint8_t *skipValue(
const uint8_t *pos) {
419 int32_t leadByte=*pos++;
420 return skipValue(pos, leadByte);
424 static const uint8_t *jumpByDelta(
const uint8_t *pos);
426 static inline const uint8_t *skipDelta(
const uint8_t *pos) {
427 int32_t delta=*pos++;
428 if(delta>=kMinTwoByteDeltaLead) {
429 if(delta<kMinThreeByteDeltaLead) {
431 }
else if(delta<kFourByteDeltaLead) {
445 UStringTrieResult branchNext(
const uint8_t *pos, int32_t length, int32_t inByte);
453 static const uint8_t *findUniqueValueFromBranch(
const uint8_t *pos, int32_t length,
454 UBool haveUniqueValue, int32_t &uniqueValue);
457 static UBool findUniqueValue(
const uint8_t *pos,
UBool haveUniqueValue, int32_t &uniqueValue);
461 static void getNextBranchBytes(
const uint8_t *pos, int32_t length, ByteSink &out);
462 static void append(ByteSink &out,
int c);
503 static const int32_t kMaxBranchLinearSubNodeLength=5;
506 static const int32_t kMinLinearMatch=0x10;
507 static const int32_t kMaxLinearMatchLength=0x10;
514 static const int32_t kMinValueLead=kMinLinearMatch+kMaxLinearMatchLength;
516 static const int32_t kValueIsFinal=1;
519 static const int32_t kMinOneByteValueLead=kMinValueLead/2;
520 static const int32_t kMaxOneByteValue=0x40;
522 static const int32_t kMinTwoByteValueLead=kMinOneByteValueLead+kMaxOneByteValue+1;
523 static const int32_t kMaxTwoByteValue=0x1aff;
525 static const int32_t kMinThreeByteValueLead=kMinTwoByteValueLead+(kMaxTwoByteValue>>8)+1;
526 static const int32_t kFourByteValueLead=0x7e;
529 static const int32_t kMaxThreeByteValue=((kFourByteValueLead-kMinThreeByteValueLead)<<16)-1;
531 static const int32_t kFiveByteValueLead=0x7f;
534 static const int32_t kMaxOneByteDelta=0xbf;
535 static const int32_t kMinTwoByteDeltaLead=kMaxOneByteDelta+1;
536 static const int32_t kMinThreeByteDeltaLead=0xf0;
537 static const int32_t kFourByteDeltaLead=0xfe;
538 static const int32_t kFiveByteDeltaLead=0xff;
540 static const int32_t kMaxTwoByteDelta=((kMinThreeByteDeltaLead-kMinTwoByteDeltaLead)<<8)-1;
541 static const int32_t kMaxThreeByteDelta=((kFourByteDeltaLead-kMinThreeByteDeltaLead)<<16)-1;
547 static constexpr int32_t kState64RemainingShift = 59;
548 static constexpr uint64_t kState64PosMask = (
UINT64_C(1) << kState64RemainingShift) - 1;
550 uint8_t *ownedArray_;
553 const uint8_t *bytes_;
560 int32_t remainingMatchLength_;
567 #endif // __BYTESTRIE_H__