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;
109 return (
static_cast<uint64_t
>(remainingMatchLength_ + 2) << kState64RemainingShift) |
110 (uint64_t)(pos_ - bytes_);
128 remainingMatchLength_ =
static_cast<int32_t
>(state >> kState64RemainingShift) - 2;
129 pos_ = bytes_ + (state & kState64PosMask);
148 const uint8_t *bytes;
150 int32_t remainingMatchLength;
163 state.remainingMatchLength=remainingMatchLength_;
178 if(bytes_==state.bytes && bytes_!=
NULL) {
180 remainingMatchLength_=state.remainingMatchLength;
202 remainingMatchLength_=-1;
206 return nextImpl(bytes_, inByte);
245 const uint8_t *pos=pos_;
246 int32_t leadByte=*pos++;
248 return readValue(pos, leadByte>>1);
261 const uint8_t *pos=pos_;
263 return pos!=
NULL && findUniqueValue(pos+remainingMatchLength_+1,
false, uniqueValue);
274 int32_t getNextBytes(
ByteSink &out)
const;
325 UBool hasNext()
const;
355 UBool truncateAndStop();
357 const uint8_t *branchNext(
const uint8_t *pos, int32_t length,
UErrorCode &errorCode);
359 const uint8_t *bytes_;
361 const uint8_t *initialPos_;
362 int32_t remainingMatchLength_;
363 int32_t initialRemainingMatchLength_;
388 BytesTrie(
void *adoptBytes,
const void *trieBytes)
389 : ownedArray_(static_cast<uint8_t *>(adoptBytes)),
390 bytes_(static_cast<const uint8_t *>(trieBytes)),
391 pos_(bytes_), remainingMatchLength_(-1) {}
394 BytesTrie &operator=(
const BytesTrie &other);
402 static int32_t readValue(
const uint8_t *pos, int32_t leadByte);
403 static inline const uint8_t *skipValue(
const uint8_t *pos, int32_t leadByte) {
405 if(leadByte>=(kMinTwoByteValueLead<<1)) {
406 if(leadByte<(kMinThreeByteValueLead<<1)) {
408 }
else if(leadByte<(kFourByteValueLead<<1)) {
411 pos+=3+((leadByte>>1)&1);
416 static inline const uint8_t *skipValue(
const uint8_t *pos) {
417 int32_t leadByte=*pos++;
418 return skipValue(pos, leadByte);
422 static const uint8_t *jumpByDelta(
const uint8_t *pos);
424 static inline const uint8_t *skipDelta(
const uint8_t *pos) {
425 int32_t delta=*pos++;
426 if(delta>=kMinTwoByteDeltaLead) {
427 if(delta<kMinThreeByteDeltaLead) {
429 }
else if(delta<kFourByteDeltaLead) {
443 UStringTrieResult branchNext(
const uint8_t *pos, int32_t length, int32_t inByte);
451 static const uint8_t *findUniqueValueFromBranch(
const uint8_t *pos, int32_t length,
452 UBool haveUniqueValue, int32_t &uniqueValue);
455 static UBool findUniqueValue(
const uint8_t *pos,
UBool haveUniqueValue, int32_t &uniqueValue);
459 static void getNextBranchBytes(
const uint8_t *pos, int32_t length, ByteSink &out);
460 static void append(ByteSink &out,
int c);
501 static const int32_t kMaxBranchLinearSubNodeLength=5;
504 static const int32_t kMinLinearMatch=0x10;
505 static const int32_t kMaxLinearMatchLength=0x10;
512 static const int32_t kMinValueLead=kMinLinearMatch+kMaxLinearMatchLength;
514 static const int32_t kValueIsFinal=1;
517 static const int32_t kMinOneByteValueLead=kMinValueLead/2;
518 static const int32_t kMaxOneByteValue=0x40;
520 static const int32_t kMinTwoByteValueLead=kMinOneByteValueLead+kMaxOneByteValue+1;
521 static const int32_t kMaxTwoByteValue=0x1aff;
523 static const int32_t kMinThreeByteValueLead=kMinTwoByteValueLead+(kMaxTwoByteValue>>8)+1;
524 static const int32_t kFourByteValueLead=0x7e;
527 static const int32_t kMaxThreeByteValue=((kFourByteValueLead-kMinThreeByteValueLead)<<16)-1;
529 static const int32_t kFiveByteValueLead=0x7f;
532 static const int32_t kMaxOneByteDelta=0xbf;
533 static const int32_t kMinTwoByteDeltaLead=kMaxOneByteDelta+1;
534 static const int32_t kMinThreeByteDeltaLead=0xf0;
535 static const int32_t kFourByteDeltaLead=0xfe;
536 static const int32_t kFiveByteDeltaLead=0xff;
538 static const int32_t kMaxTwoByteDelta=((kMinThreeByteDeltaLead-kMinTwoByteDeltaLead)<<8)-1;
539 static const int32_t kMaxThreeByteDelta=((kFourByteDeltaLead-kMinThreeByteDeltaLead)<<16)-1;
545 static constexpr int32_t kState64RemainingShift = 59;
546 static constexpr uint64_t kState64PosMask = (
UINT64_C(1) << kState64RemainingShift) - 1;
548 uint8_t *ownedArray_;
551 const uint8_t *bytes_;
558 int32_t remainingMatchLength_;
565 #endif // __BYTESTRIE_H__