A Trie String lookup data structure using a fixed size array.
This implementation is always case insensitive and is optimal for a small number of fixed strings with few special characters. The Trie is stored in an array of lookup tables, each indexed by the next character of the key. Frequently used characters are directly indexed in each lookup table, whilst infrequently used characters must use a big character table.
This Trie is space efficient if the key characters are from ' ', '+', '-', ':', ';', '.', '0' - '9', A' to 'Z' or 'a' to 'z' Other ISO-8859-1 characters can be used by the key, but less space efficiently.
This Trie is not Threadsafe and contains no mutual exclusion or deliberate memory barriers. It is intended for an ArrayTrie to be built by a single thread and then used concurrently by multiple threads and not mutated during that access. If concurrent mutations of the Trie is required external locks need to be applied.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final int[] | |
| private final ArrayTrie. | |
| private char | |
| private final char[] | _table
The Trie rows in a single array which allows a lookup of row,character to the next row in the Trie. |
| private static final int | |
| private static final int | |
| private static final int[] | LOOKUP_INSENSITIVE
The index lookup table, this maps a character as a byte (ISO-8859-1 or UTF8) to a Trie index within a Trie row. |
| private static final int[] | LOOKUP_SENSITIVE
The index lookup table, this maps a character as a byte (ISO-8859-1 or UTF8) to a Trie index within a Trie row. |
| public static int | |
| private static final int | ROW_SIZE
The Size of a Trie row is how many characters can be looked up directly without going to a big index. |
| private static final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | ArrayTrie(int
The capacity of the trie, which at the worst case
is the total number of characters of all keys stored in the Trie,
plus 1 for the empty key. capacity)
|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public static < The value type of the Trie V> ArrayTrie | Returns: a Trie containing the contents or null if not possible.The maximum capacity of the Trie or -1 for unlimited capacity capacity, boolean True if the Trie keys are case sensitive caseSensitive, Map<String, V> The known contents of the Trie contents)Create a trie from capacity and content |
| public V | get(String
The key s, int The offset within the string of the key offset, int the length of the key len)Implements org. Get an exact match from a String key |
| public V | get(ByteBuffer
The buffer b, int The offset within the buffer of the key offset, int the length of the key len)Implements org. Get an exact match from a segment of a ByteBuffer as key |
| public V | getBest(byte[]
The buffer b, int The offset within the array of the key offset, int the length of the key len)Overrides org. Implements org. Get the best match from key in a byte array. |
| public V | getBest(ByteBuffer
The buffer b, int The offset within the buffer of the key offset, int the length of the key len)Implements org. Get the best match from key in a byte buffer. |
| public V | getBest(String
The string s, int The offset within the string of the key offset, int the length of the key len)Implements org. Get the best match from key in a String. |
| private V | |
| private V | |
| private V | |
| public boolean | |
| public Set | keySet()
Implements org. Get a |
| private int | |
| public boolean | put(String
The key for the entry. Must be non null, but can be empty. key, V The value of the entry. Must be non null. value)Implements org. Put an entry into the index. |
| public int | |
| public String |
| _bigRowSize | back to summary |
|---|---|
| private final int _bigRowSize | |
| _lookup | back to summary |
|---|---|
| private final int[] _lookup | |
| _node | back to summary |
|---|---|
| private final ArrayTrie. | |
| _rows | back to summary |
|---|---|
| private char _rows | |
| _table | back to summary |
|---|---|
| private final char[] _table The Trie rows in a single array which allows a lookup of row,character to the next row in the Trie. This is actually a 2 dimensional array that has been flattened to achieve locality of reference. The first ROW_SIZE entries are for row 0, then next ROW_SIZE entries are for row 1 etc. So in general instead of using _rows[row][column], we use _rows[row*ROW_SIZE+column] to look up the next row for a given character. The array is of characters rather than integers to save space. | |
| BIG_ROW_INSENSITIVE | back to summary |
|---|---|
| private static final int BIG_ROW_INSENSITIVE | |
| BIG_ROW_SENSITIVE | back to summary |
|---|---|
| private static final int BIG_ROW_SENSITIVE | |
| LOOKUP_INSENSITIVE | back to summary |
|---|---|
| private static final int[] LOOKUP_INSENSITIVE The index lookup table, this maps a character as a byte
(ISO-8859-1 or UTF8) to a Trie index within a Trie row.
Positive values are column indexes within the main | |
| LOOKUP_SENSITIVE | back to summary |
|---|---|
| private static final int[] LOOKUP_SENSITIVE The index lookup table, this maps a character as a byte
(ISO-8859-1 or UTF8) to a Trie index within a Trie row.
Positive values are column indexes within the main | |
| MAX_CAPACITY | back to summary |
|---|---|
| public static int MAX_CAPACITY | |
| ROW_SIZE | back to summary |
|---|---|
| private static final int ROW_SIZE The Size of a Trie row is how many characters can be looked up directly without going to a big index. This is set at 32 to cover case insensitive alphabet and a few other common characters. | |
| X | back to summary |
|---|---|
| private static final int X | |
| ArrayTrie | back to summary |
|---|---|
pack-priv ArrayTrie(int capacity)
| |
| ArrayTrie | back to summary |
|---|---|
pack-priv ArrayTrie(boolean caseSensitive, int capacity)
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Remove all entries from the index.
| |
| dumpStdErr | back to summary |
|---|---|
| public void dumpStdErr() | |
| from | back to summary |
|---|---|
| public static <V> ArrayTrie Create a trie from capacity and content
| |
| get | back to summary |
|---|---|
| public V get(String s, int offset, int len) Implements org. Doc from org. Get an exact match from a String key | |
| get | back to summary |
|---|---|
| public V get(ByteBuffer b, int offset, int len) Implements org. Doc from org. Get an exact match from a segment of a ByteBuffer as key
| |
| getBest | back to summary |
|---|---|
| public V getBest(byte[] b, int offset, int len) Overrides org. Implements org. Doc from org. Get the best match from key in a byte array. The key is assumed to by ISO_8859_1 characters.
| |
| getBest | back to summary |
|---|---|
| public V getBest(ByteBuffer b, int offset, int len) Implements org. Doc from org. Get the best match from key in a byte buffer. The key is assumed to by ISO_8859_1 characters.
| |
| getBest | back to summary |
|---|---|
| public V getBest(String s, int offset, int len) Implements org. Doc from org. Get the best match from key in a String. | |
| getBest | back to summary |
|---|---|
| private V getBest(int row, String s, int offset, int len) | |
| getBest | back to summary |
|---|---|
| private V getBest(int row, byte[] b, int offset, int len) | |
| getBest | back to summary |
|---|---|
| private V getBest(int row, ByteBuffer b, int offset, int len) | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements org. Doc from org. Check if the index contains any entry.
| |
| keySet | back to summary |
|---|---|
| public Set Implements org. Doc from org. Get a | |
| lookup | back to summary |
|---|---|
| private int lookup(int row, char c) | |
| put | back to summary |
|---|---|
| public boolean put(String key, V value) Implements org. Doc from org. Put an entry into the index. | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Get the number of entries in the index.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
_table array
that either have a key/value pair or a _bigRow extended row.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv char[] | _bigRow
A big row of indexes in which extended characters can be found. |
| pack-priv String | |
| pack-priv V |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public String |
| _bigRow | back to summary |
|---|---|
| pack-priv char[] _bigRow A big row of indexes in which extended characters can be found.
The first | |
| _key | back to summary |
|---|---|
| pack-priv String _key | |
| _value | back to summary |
|---|---|
| pack-priv V _value | |
| Node | back to summary |
|---|---|
| private Node() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |