ICU 4.8.1.1  4.8.1.1
Data Structures | Public Member Functions | Friends
BytesTrie Class Reference

Light-weight, non-const reader class for a BytesTrie. More...

#include <bytestrie.h>

Inheritance diagram for BytesTrie:
UMemory

Data Structures

class  Iterator
 Iterator for all of the (byte sequence, value) pairs in a BytesTrie. More...
class  State
 BytesTrie state object, for saving a trie's current state and resetting the trie back to this state later. More...

Public Member Functions

 BytesTrie (const void *trieBytes)
 Constructs a BytesTrie reader instance.
 ~BytesTrie ()
 Destructor.
 BytesTrie (const BytesTrie &other)
 Copy constructor, copies the other trie reader object and its state, but not the byte array which will be shared.
BytesTriereset ()
 Resets this trie to its initial state.
const BytesTriesaveState (State &state) const
 Saves the state of this trie.
BytesTrieresetToState (const State &state)
 Resets this trie to the saved state.
UStringTrieResult current () const
 Determines whether the byte sequence so far matches, whether it has a value, and whether another input byte can continue a matching byte sequence.
UStringTrieResult first (int32_t inByte)
 Traverses the trie from the initial state for this input byte.
UStringTrieResult next (int32_t inByte)
 Traverses the trie from the current state for this input byte.
UStringTrieResult next (const char *s, int32_t length)
 Traverses the trie from the current state for this byte sequence.
int32_t getValue () const
 Returns a matching byte sequence's value if called immediately after current()/first()/next() returned USTRINGTRIE_INTERMEDIATE_VALUE or USTRINGTRIE_FINAL_VALUE.
UBool hasUniqueValue (int32_t &uniqueValue) const
 Determines whether all byte sequences reachable from the current state map to the same value.
int32_t getNextBytes (ByteSink &out) const
 Finds each byte which continues the byte sequence from the current state.

Friends

class BytesTrieBuilder

Detailed Description

Light-weight, non-const reader class for a BytesTrie.

Traverses a byte-serialized data structure with minimal state, for mapping byte sequences to non-negative integer values.

This class owns the serialized trie data only if it was constructed by the builder's build() method. The public constructor and the copy constructor only alias the data (only copy the pointer). There is no assignment operator.

This class is not intended for public subclassing.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 48 of file bytestrie.h.


Constructor & Destructor Documentation

BytesTrie::BytesTrie ( const void *  trieBytes) [inline]

Constructs a BytesTrie reader instance.

The trieBytes must contain a copy of a byte sequence from the BytesTrieBuilder, starting with the first byte of that sequence. The BytesTrie object will not read more bytes than the BytesTrieBuilder generated in the corresponding build() call.

The array is not copied/cloned and must not be modified while the BytesTrie object is in use.

Parameters:
trieBytesThe byte array that contains the serialized trie.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 64 of file bytestrie.h.

Destructor.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
BytesTrie::BytesTrie ( const BytesTrie other) [inline]

Copy constructor, copies the other trie reader object and its state, but not the byte array which will be shared.

(Shallow copy.)

Parameters:
otherAnother BytesTrie object.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 80 of file bytestrie.h.


Member Function Documentation

Determines whether the byte sequence so far matches, whether it has a value, and whether another input byte can continue a matching byte sequence.

Returns:
The match/value Result.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Traverses the trie from the initial state for this input byte.

Equivalent to reset().next(inByte).

Parameters:
inByteInput byte value. Values -0x100..-1 are treated like 0..0xff. Values below -0x100 and above 0xff will never match.
Returns:
The match/value Result.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 163 of file bytestrie.h.

Finds each byte which continues the byte sequence from the current state.

That is, each byte b for which it would be next(b)!=USTRINGTRIE_NO_MATCH now.

Parameters:
outEach next byte is appended to this object. (Only uses the out.Append(s, length) method.)
Returns:
the number of bytes which continue the byte sequence from here
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
int32_t BytesTrie::getValue ( ) const [inline]

Returns a matching byte sequence's value if called immediately after current()/first()/next() returned USTRINGTRIE_INTERMEDIATE_VALUE or USTRINGTRIE_FINAL_VALUE.

getValue() can be called multiple times.

Do not call getValue() after USTRINGTRIE_NO_MATCH or USTRINGTRIE_NO_VALUE!

Returns:
The value for the byte sequence so far.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 206 of file bytestrie.h.

UBool BytesTrie::hasUniqueValue ( int32_t uniqueValue) const [inline]

Determines whether all byte sequences reachable from the current state map to the same value.

Parameters:
uniqueValueReceives the unique value, if this function returns TRUE. (output-only)
Returns:
TRUE if all byte sequences reachable from the current state map to the same value.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 222 of file bytestrie.h.

References FALSE, and NULL.

Traverses the trie from the current state for this input byte.

Parameters:
inByteInput byte value. Values -0x100..-1 are treated like 0..0xff. Values below -0x100 and above 0xff will never match.
Returns:
The match/value Result.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
UStringTrieResult BytesTrie::next ( const char *  s,
int32_t  length 
)

Traverses the trie from the current state for this byte sequence.

Equivalent to

 Result result=current();
 for(each c in s)
   if(!USTRINGTRIE_HAS_NEXT(result)) return USTRINGTRIE_NO_MATCH;
   result=next(c);
 return result;
Parameters:
sA string or byte sequence. Can be NULL if length is 0.
lengthThe length of the byte sequence. Can be -1 if NUL-terminated.
Returns:
The match/value Result.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
BytesTrie& BytesTrie::reset ( ) [inline]

Resets this trie to its initial state.

Returns:
*this
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 89 of file bytestrie.h.

BytesTrie& BytesTrie::resetToState ( const State state) [inline]

Resets this trie to the saved state.

If the state object contains no state, or the state of a different trie, then this trie remains unchanged.

Parameters:
stateThe State object which holds a saved trie state.
Returns:
*this
See also:
saveState
reset
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 139 of file bytestrie.h.

References NULL.

const BytesTrie& BytesTrie::saveState ( State state) const [inline]

Saves the state of this trie.

Parameters:
stateThe State object to hold the trie's state.
Returns:
*this
See also:
resetToState
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 122 of file bytestrie.h.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines