public final class BytesTrie extends Object implements Cloneable, Iterable<BytesTrie.Entry>
This class is not intended for public subclassing.
Modifier and Type | Class and Description |
---|---|
static class |
BytesTrie.Entry
Return value type for the Iterator.
|
static class |
BytesTrie.Iterator
Iterator for all of the (byte sequence, value) pairs in a BytesTrie.
|
static class |
BytesTrie.Result
Return values for BytesTrie.next(), CharsTrie.next() and similar methods.
|
static class |
BytesTrie.State
BytesTrie state object, for saving a trie's current state
and resetting the trie back to this state later.
|
Constructor and Description |
---|
BytesTrie(byte[] trieBytes,
int offset)
Constructs a BytesTrie reader instance.
|
BytesTrie(BytesTrie other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
BytesTrie |
clone()
Clones this trie reader object and its state,
but not the byte array which will be shared.
|
BytesTrie.Result |
current()
Determines whether the byte sequence so far matches, whether it has a value,
and whether another input byte can continue a matching byte sequence.
|
BytesTrie.Result |
first(int inByte)
Traverses the trie from the initial state for this input byte.
|
int |
getNextBytes(Appendable out)
Finds each byte which continues the byte sequence from the current state.
|
long |
getState64()
Returns the state of this trie as a 64-bit integer.
|
long |
getUniqueValue()
Determines whether all byte sequences reachable from the current state
map to the same value, and if so, returns that value.
|
int |
getValue()
Returns a matching byte sequence's value if called immediately after
current()/first()/next() returned Result.INTERMEDIATE_VALUE or Result.FINAL_VALUE.
|
BytesTrie.Iterator |
iterator()
Iterates from the current state of this trie.
|
static BytesTrie.Iterator |
iterator(byte[] trieBytes,
int offset,
int maxStringLength)
Iterates from the root of a byte-serialized BytesTrie.
|
BytesTrie.Iterator |
iterator(int maxStringLength)
Iterates from the current state of this trie.
|
static int |
jumpByDelta(byte[] bytes,
int pos)
Deprecated.
This API is ICU internal only.
|
BytesTrie.Result |
next(byte[] s,
int sIndex,
int sLimit)
Traverses the trie from the current state for this byte sequence.
|
BytesTrie.Result |
next(int inByte)
Traverses the trie from the current state for this input byte.
|
BytesTrie |
reset()
Resets this trie to its initial state.
|
BytesTrie |
resetToState(BytesTrie.State state)
Resets this trie to the saved state.
|
BytesTrie |
resetToState64(long state)
Resets this trie to the saved state.
|
BytesTrie |
saveState(BytesTrie.State state)
Saves the state of this trie.
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public BytesTrie(byte[] trieBytes, int offset)
The array must contain a copy of a byte sequence from the BytesTrieBuilder, with the offset indicating 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.
trieBytes
- Bytes array that contains the serialized trie.offset
- Root offset of the trie in the array.public BytesTrie(BytesTrie other)
public BytesTrie clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public BytesTrie reset()
public long getState64()
resetToState64(long)
public BytesTrie resetToState64(long state)
resetToState(State)
, the 64-bit state value
must be from getState64()
from the same trie object or
from one initialized the exact same way.
Because of no validation, this method is faster.state
- The opaque trie state value from getState64().getState64()
,
resetToState(com.ibm.icu.util.BytesTrie.State)
,
reset()
public BytesTrie saveState(BytesTrie.State state)
state
- The State object to hold the trie's state.resetToState(com.ibm.icu.util.BytesTrie.State)
public BytesTrie resetToState(BytesTrie.State state)
resetToState64(long)
which does not validate the state value.state
- The State object which holds a saved trie state.IllegalArgumentException
- if the state object contains no state,
or the state of a different triesaveState(com.ibm.icu.util.BytesTrie.State)
,
reset()
public BytesTrie.Result current()
public BytesTrie.Result first(int inByte)
inByte
- Input byte value. Values -0x100..-1 are treated like 0..0xff.
Values below -0x100 and above 0xff will never match.public BytesTrie.Result next(int inByte)
inByte
- Input byte value. Values -0x100..-1 are treated like 0..0xff.
Values below -0x100 and above 0xff will never match.public BytesTrie.Result next(byte[] s, int sIndex, int sLimit)
Result result=current(); for(each c in s) if(!result.hasNext()) return Result.NO_MATCH; result=next(c); return result;
s
- Contains a string or byte sequence.sIndex
- The start index of the byte sequence in s.sLimit
- The (exclusive) end index of the byte sequence in s.public int getValue()
public long getUniqueValue()
public int getNextBytes(Appendable out)
out
- Each next byte is 0-extended to a char and appended to this object.
(Only uses the out.append(c) method.)public BytesTrie.Iterator iterator()
iterator
in interface Iterable<BytesTrie.Entry>
public BytesTrie.Iterator iterator(int maxStringLength)
maxStringLength
- If 0, the iterator returns full strings/byte sequences.
Otherwise, the iterator returns strings with this maximum length.public static BytesTrie.Iterator iterator(byte[] trieBytes, int offset, int maxStringLength)
trieBytes
- Bytes array that contains the serialized trie.offset
- Root offset of the trie in the array.maxStringLength
- If 0, the iterator returns full strings/byte sequences.
Otherwise, the iterator returns strings with this maximum length.@Deprecated public static int jumpByDelta(byte[] bytes, int pos)
Copyright © 2016 Unicode, Inc. and others.