15 #ifndef __BYTESTRIE_H__
16 #define __BYTESTRIE_H__
65 : ownedArray_(
NULL), bytes_(reinterpret_cast<const uint8_t *>(trieBytes)),
66 pos_(bytes_), remainingMatchLength_(-1) {}
81 : ownedArray_(
NULL), bytes_(other.bytes_),
82 pos_(other.pos_), remainingMatchLength_(other.remainingMatchLength_) {}
91 remainingMatchLength_=-1;
110 const uint8_t *bytes;
112 int32_t remainingMatchLength;
125 state.remainingMatchLength=remainingMatchLength_;
140 if(bytes_==state.bytes && bytes_!=
NULL) {
142 remainingMatchLength_=state.remainingMatchLength;
164 remainingMatchLength_=-1;
168 return nextImpl(bytes_, inByte);
207 const uint8_t *pos=pos_;
208 int32_t leadByte=*pos++;
210 return readValue(pos, leadByte>>1);
223 const uint8_t *pos=pos_;
225 return pos!=
NULL && findUniqueValue(pos+remainingMatchLength_+1,
FALSE, uniqueValue);
287 UBool hasNext()
const;
317 UBool truncateAndStop();
319 const uint8_t *branchNext(
const uint8_t *pos, int32_t length,
UErrorCode &errorCode);
321 const uint8_t *bytes_;
323 const uint8_t *initialPos_;
324 int32_t remainingMatchLength_;
325 int32_t initialRemainingMatchLength_;
351 BytesTrie(
void *adoptBytes,
const void *trieBytes)
352 : ownedArray_(reinterpret_cast<uint8_t *>(adoptBytes)),
353 bytes_(reinterpret_cast<const uint8_t *>(trieBytes)),
354 pos_(bytes_), remainingMatchLength_(-1) {}
365 static int32_t readValue(
const uint8_t *pos, int32_t leadByte);
366 static inline const uint8_t *skipValue(
const uint8_t *pos, int32_t leadByte) {
368 if(leadByte>=(kMinTwoByteValueLead<<1)) {
369 if(leadByte<(kMinThreeByteValueLead<<1)) {
371 }
else if(leadByte<(kFourByteValueLead<<1)) {
374 pos+=3+((leadByte>>1)&1);
379 static inline const uint8_t *skipValue(
const uint8_t *pos) {
380 int32_t leadByte=*pos++;
381 return skipValue(pos, leadByte);
385 static const uint8_t *jumpByDelta(
const uint8_t *pos);
387 static inline const uint8_t *skipDelta(
const uint8_t *pos) {
388 int32_t delta=*pos++;
389 if(delta>=kMinTwoByteDeltaLead) {
390 if(delta<kMinThreeByteDeltaLead) {
392 }
else if(delta<kFourByteDeltaLead) {
406 UStringTrieResult branchNext(
const uint8_t *pos, int32_t length, int32_t inByte);
414 static const uint8_t *findUniqueValueFromBranch(
const uint8_t *pos, int32_t length,
415 UBool haveUniqueValue, int32_t &uniqueValue);
418 static UBool findUniqueValue(
const uint8_t *pos,
UBool haveUniqueValue, int32_t &uniqueValue);
422 static void getNextBranchBytes(
const uint8_t *pos, int32_t length,
ByteSink &out);
423 static void append(
ByteSink &out,
int c);
467 static const int32_t kMinLinearMatch=0x10;
468 static const int32_t kMaxLinearMatchLength=0x10;
475 static const int32_t kMinValueLead=kMinLinearMatch+kMaxLinearMatchLength;
477 static const int32_t kValueIsFinal=1;
480 static const int32_t kMinOneByteValueLead=kMinValueLead/2;
481 static const int32_t kMaxOneByteValue=0x40;
483 static const int32_t kMinTwoByteValueLead=kMinOneByteValueLead+kMaxOneByteValue+1;
484 static const int32_t kMaxTwoByteValue=0x1aff;
486 static const int32_t kMinThreeByteValueLead=kMinTwoByteValueLead+(kMaxTwoByteValue>>8)+1;
487 static const int32_t kFourByteValueLead=0x7e;
490 static const int32_t kMaxThreeByteValue=((kFourByteValueLead-kMinThreeByteValueLead)<<16)-1;
492 static const int32_t kFiveByteValueLead=0x7f;
495 static const int32_t kMaxOneByteDelta=0xbf;
496 static const int32_t kMinTwoByteDeltaLead=kMaxOneByteDelta+1;
497 static const int32_t kMinThreeByteDeltaLead=0xf0;
498 static const int32_t kFourByteDeltaLead=0xfe;
499 static const int32_t kFiveByteDeltaLead=0xff;
501 static const int32_t kMaxTwoByteDelta=((kMinThreeByteDeltaLead-kMinTwoByteDeltaLead)<<8)-1;
502 static const int32_t kMaxThreeByteDelta=((kFourByteDeltaLead-kMinThreeByteDeltaLead)<<16)-1;
504 uint8_t *ownedArray_;
507 const uint8_t *bytes_;
514 int32_t remainingMatchLength_;
519 #endif // __BYTESTRIE_H__