17 #ifndef __BYTESTRIE_H__ 18 #define __BYTESTRIE_H__ 33 class BytesTrieBuilder;
67 : ownedArray_(
NULL), bytes_(static_cast<const uint8_t *>(trieBytes)),
68 pos_(bytes_), remainingMatchLength_(-1) {}
83 : ownedArray_(
NULL), bytes_(other.bytes_),
84 pos_(other.pos_), remainingMatchLength_(other.remainingMatchLength_) {}
93 remainingMatchLength_=-1;
112 const uint8_t *bytes;
114 int32_t remainingMatchLength;
127 state.remainingMatchLength=remainingMatchLength_;
142 if(bytes_==state.bytes && bytes_!=
NULL) {
144 remainingMatchLength_=state.remainingMatchLength;
166 remainingMatchLength_=-1;
170 return nextImpl(bytes_, inByte);
209 const uint8_t *pos=pos_;
210 int32_t leadByte=*pos++;
212 return readValue(pos, leadByte>>1);
225 const uint8_t *pos=pos_;
227 return pos!=
NULL && findUniqueValue(pos+remainingMatchLength_+1,
FALSE, uniqueValue);
238 int32_t getNextBytes(
ByteSink &out)
const;
289 UBool hasNext()
const;
319 UBool truncateAndStop();
321 const uint8_t *branchNext(
const uint8_t *pos, int32_t length,
UErrorCode &errorCode);
323 const uint8_t *bytes_;
325 const uint8_t *initialPos_;
326 int32_t remainingMatchLength_;
327 int32_t initialRemainingMatchLength_;
352 BytesTrie(
void *adoptBytes,
const void *trieBytes)
353 : ownedArray_(static_cast<uint8_t *>(adoptBytes)),
354 bytes_(static_cast<const uint8_t *>(trieBytes)),
355 pos_(bytes_), remainingMatchLength_(-1) {}
366 static int32_t readValue(
const uint8_t *pos, int32_t leadByte);
367 static inline const uint8_t *skipValue(
const uint8_t *pos, int32_t leadByte) {
369 if(leadByte>=(kMinTwoByteValueLead<<1)) {
370 if(leadByte<(kMinThreeByteValueLead<<1)) {
372 }
else if(leadByte<(kFourByteValueLead<<1)) {
375 pos+=3+((leadByte>>1)&1);
380 static inline const uint8_t *skipValue(
const uint8_t *pos) {
381 int32_t leadByte=*pos++;
382 return skipValue(pos, leadByte);
386 static const uint8_t *jumpByDelta(
const uint8_t *pos);
388 static inline const uint8_t *skipDelta(
const uint8_t *pos) {
389 int32_t delta=*pos++;
390 if(delta>=kMinTwoByteDeltaLead) {
391 if(delta<kMinThreeByteDeltaLead) {
393 }
else if(delta<kFourByteDeltaLead) {
407 UStringTrieResult branchNext(
const uint8_t *pos, int32_t length, int32_t inByte);
415 static const uint8_t *findUniqueValueFromBranch(
const uint8_t *pos, int32_t length,
416 UBool haveUniqueValue, int32_t &uniqueValue);
419 static UBool findUniqueValue(
const uint8_t *pos,
UBool haveUniqueValue, int32_t &uniqueValue);
423 static void getNextBranchBytes(
const uint8_t *pos, int32_t length,
ByteSink &out);
424 static void append(
ByteSink &out,
int c);
465 static const int32_t kMaxBranchLinearSubNodeLength=5;
468 static const int32_t kMinLinearMatch=0x10;
469 static const int32_t kMaxLinearMatchLength=0x10;
476 static const int32_t kMinValueLead=kMinLinearMatch+kMaxLinearMatchLength;
478 static const int32_t kValueIsFinal=1;
481 static const int32_t kMinOneByteValueLead=kMinValueLead/2;
482 static const int32_t kMaxOneByteValue=0x40;
484 static const int32_t kMinTwoByteValueLead=kMinOneByteValueLead+kMaxOneByteValue+1;
485 static const int32_t kMaxTwoByteValue=0x1aff;
487 static const int32_t kMinThreeByteValueLead=kMinTwoByteValueLead+(kMaxTwoByteValue>>8)+1;
488 static const int32_t kFourByteValueLead=0x7e;
491 static const int32_t kMaxThreeByteValue=((kFourByteValueLead-kMinThreeByteValueLead)<<16)-1;
493 static const int32_t kFiveByteValueLead=0x7f;
496 static const int32_t kMaxOneByteDelta=0xbf;
497 static const int32_t kMinTwoByteDeltaLead=kMaxOneByteDelta+1;
498 static const int32_t kMinThreeByteDeltaLead=0xf0;
499 static const int32_t kFourByteDeltaLead=0xfe;
500 static const int32_t kFiveByteDeltaLead=0xff;
502 static const int32_t kMaxTwoByteDelta=((kMinThreeByteDeltaLead-kMinTwoByteDeltaLead)<<8)-1;
503 static const int32_t kMaxThreeByteDelta=((kFourByteDeltaLead-kMinThreeByteDeltaLead)<<16)-1;
505 uint8_t *ownedArray_;
508 const uint8_t *bytes_;
515 int32_t remainingMatchLength_;
520 #endif // __BYTESTRIE_H__ Builder class for BytesTrie.
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.
A ByteSink can be filled with bytes.
UBool hasUniqueValue(int32_t &uniqueValue) const
Determines whether all byte sequences reachable from the current state map to the same value...
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.
int32_t getValue() const
Returns a matching byte sequence's value if called immediately after current()/first()/next() returne...
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 nullptr 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.
const BytesTrie & saveState(State &state) const
Saves the state of this trie.
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.