15 #ifndef __BYTESTRIE_H__
16 #define __BYTESTRIE_H__
31 class BytesTrieBuilder;
65 : ownedArray_(
NULL), bytes_(static_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);
236 int32_t getNextBytes(
ByteSink &out)
const;
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_(static_cast<uint8_t *>(adoptBytes)),
353 bytes_(static_cast<const uint8_t *>(trieBytes)),
354 pos_(bytes_), remainingMatchLength_(-1) {}
357 BytesTrie &operator=(
const BytesTrie &other);
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);
464 static const int32_t kMaxBranchLinearSubNodeLength=5;
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__
Builder class for BytesTrie.
const BytesTrie & saveState(State &state) const
Saves the state of this trie.
BytesTrie state object, for saving a trie's current state and resetting the trie back to this state l...
UStringTrieResult
Return values for BytesTrie::next(), UCharsTrie::next() and similar methods.
BytesTrie(const void *trieBytes)
Constructs a BytesTrie reader instance.
const StringPiece & getString() const
A ByteSink can be filled with bytes.
int32_t getValue() const
Returns a matching byte sequence's value if called immediately after current()/first()/next() returne...
Light-weight, non-const reader class for a BytesTrie.
BytesTrie & reset()
Resets this trie to its initial state.
C++ API: StringPiece: Read-only byte string wrapper class.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
UStringTrieResult first(int32_t inByte)
Traverses the trie from the initial state for this input byte.
UBool hasUniqueValue(int32_t &uniqueValue) const
Determines whether all byte sequences reachable from the current state map to the same value...
BytesTrie(const BytesTrie &other)
Copy constructor, copies the other trie reader object and its state, but not the byte array which wil...
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
State()
Constructs an empty State.
Iterator for all of the (byte sequence, value) pairs in a BytesTrie.
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
C API: Helper definitions for dictionary trie APIs.
Basic definitions for ICU, for both C and C++ APIs.
#define FALSE
The FALSE value of a UBool.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
The input unit(s) continued a matching string and there is a value for the string so far...
A string-like object that points to a sized piece of memory.
BytesTrie & resetToState(const State &state)
Resets this trie to the saved state.
UMemory is the common ICU base class.
int8_t UBool
The ICU boolean type.