Package com.pnfsoftware.jeb.util.collect
Class CFBytesTrie<T>
java.lang.Object
com.pnfsoftware.jeb.util.collect.CFBytesTrie<T>
- Type Parameters:
T- value type
A trie map specialized to handle context-free (CF) binary strings. Context-free here means that
the binary strings stored as keys cannot be such that, given a binary string A, there exists a
longer binary string B whose prefix is A.
Characteristics/limitations:
- Support for insertion and retrieval only (no removal).
- The null key and the empty key are illegal.
- Null values are illegal.
This class is not thread-safe. This class does not override equals/hashCode/toString.
Implementation notes: this class is serializable (provided that the stored objects T are also
serializable). In order to serialize this class efficiently, both in terms of space and time, a
key extractor should be set.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe key extractor provides the bytes used in the trie for an element.static classA node in the trie. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all entries.Format internal trie statistics.get(byte[] key, boolean exactKey) Retrieve a value in the trie.get(byte[] keyarray, int start, int max, boolean exactKey) Retrieve a value in the trie.getItems()Generate the list of items (key, value) stored in this trie.Generate a list of all values stored in this trie.booleanisEmpty()Add a new entry to the trie.voidAdd a new entry to the trie.voidAdd a new entry to the trie.booleanAdd a new entry to the trie.voidsetKeyExtractor(CFBytesTrie.IKeyExtractor<T> keyExtractor) Set the key extractor used byput(Object)and optimized serialization.intsize()
-
Constructor Details
-
CFBytesTrie
public CFBytesTrie()Create an empty trie.
-
-
Method Details
-
setKeyExtractor
Set the key extractor used byput(Object)and optimized serialization.- Parameters:
keyExtractor- key extractor
-
getKeyExtractor
- Returns:
- configured key extractor, or null
-
clear
public void clear()Remove all entries. -
size
public int size()- Returns:
- number of entries
-
isEmpty
public boolean isEmpty()- Returns:
- true if the trie is empty
-
put
Add a new entry to the trie. This method throws anIllegalStateExceptionon prefix collision.- Parameters:
object- value (the value's key is derived using the key extractor)
-
put
Add a new entry to the trie. This method throws anIllegalStateExceptionon prefix collision.- Parameters:
key- keyobject- value
-
put
Add a new entry to the trie. This method throws anIllegalStateExceptionon prefix collision.- Parameters:
keyarray- key arraystart- key start position in the arrayend- key end position (exclusive)object- value- Returns:
- the previous entry at key, null if none
-
putSafe
Add a new entry to the trie. This method does not throw if a prefix collision is detected; instead, false is returned.- Parameters:
keyarray- key arraystart- key start position in the arrayend- key end position (exclusive)object- valueaprev- if non-null, a one-element array that will receive the previous entry at key, or null if none- Returns:
- success indicator (false if a prefix collision occurred)
-
get
Retrieve a value in the trie.- Parameters:
key- keyexactKey- true to require an exact key match- Returns:
- object value, null if none
-
get
Retrieve a value in the trie.- Parameters:
keyarray- key arraystart- key start indexmax- key end index (exclusive)exactKey- if false, more potential key bytes may be provided, and the object whose key matches the beginning of the sequence of bytes will be returned- Returns:
- object value, null if none
-
formatInternalState
Format internal trie statistics.- Returns:
- formatted state string
-
getValues
Generate a list of all values stored in this trie. This method is potentially expensive.- Returns:
- list of stored values
-
getItems
Generate the list of items (key, value) stored in this trie. This method is potentially expensive.- Returns:
- list of stored key-value pairs
-