Package com.pnfsoftware.jeb.util.collect
Class CFBytesTrie<T>
java.lang.Object
com.pnfsoftware.jeb.util.collect.CFBytesTrie<T>
- Type Parameters:
T
-
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: the is serializable (at the condition 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 interface
The key extractor provides the bytes (to be used in the trie) for an element to be stored in the trie.static class
A node in the trie. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
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.boolean
isEmpty()
Add a new entry to the trie.void
Add a new entry to the trie.void
Add a new entry to the trie.boolean
Add a new entry to the trie.void
setKeyExtractor
(CFBytesTrie.IKeyExtractor<T> keyExtractor) int
size()
-
Constructor Details
-
CFBytesTrie
public CFBytesTrie()
-
-
Method Details
-
setKeyExtractor
-
getKeyExtractor
-
clear
public void clear() -
size
public int size() -
isEmpty
public boolean isEmpty() -
put
Add a new entry to the trie. This method throws anIllegalStateException
on 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 anIllegalStateException
on prefix collision.- Parameters:
key
- keyobject
- value
-
put
Add a new entry to the trie. This method throws anIllegalStateException
on 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
-- 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
-
getValues
Generate a list of all values stored in this trie. This method is potentially expensive.- Returns:
-
getItems
Generate the list of items (key, value) stored in this trie. This method is potentially expensive.- Returns:
-