E - public class MultithreadedStringTrie<E> extends Object implements PrefixedMap<E>
It exists in a cleaner form in the labs module, but it was good enough to act as a high-performance solution in multi-threaded environments.
It is really only used for our classpath scanner, which can beat java.util concurrent maps in heavily threaded enviros
Trie walking locks safely, but with minimal hold times, so contention during concurrent operations will only occur if the keys overlap. Once one thread is ahead of another, it will stay ahead of others.
This class should NOT be used anywhere that doesn't explicitly need Trie behavior in multi-threaded enviros. It's not optimized for lookup time yet.
Application-wide, java-package based keys are good candidates for StringTrie.
Production Trie versions will be suitable for tasks like type-ahead, with O(log(m)) lookup, where m = string length instead of n = collection size.
The in-progress upgrade to this class will include array-based deep node support, so nodes with more than two branches can do faster lookup.
| Modifier and Type | Class and Description |
|---|---|
class |
MultithreadedStringTrie.Edge
Our Edge class is one node in the Trie graph.
|
protected class |
MultithreadedStringTrie.Itr |
| Modifier and Type | Field and Description |
|---|---|
protected MultithreadedStringTrie.Edge |
root |
| Constructor and Description |
|---|
MultithreadedStringTrie() |
| Modifier and Type | Method and Description |
|---|---|
void |
compress(CharPool charPoolTrie) |
protected void |
doPut(MultithreadedStringTrie.Edge into,
char[] key,
int index,
int end,
E value) |
Iterable<E> |
findPrefixed(String prefix) |
E |
get(char[] key) |
E |
get(char[] key,
int pos,
int end) |
E |
get(Chars keys,
int pos,
int end) |
E |
get(String key) |
protected void |
lock(MultithreadedStringTrie.Edge into,
boolean ownsParent) |
protected MultithreadedStringTrie.Edge |
newEdge() |
protected MultithreadedStringTrie.Edge |
newEdge(char[] key,
int index,
int end,
E value) |
protected MultithreadedStringTrie.Edge |
newEdgeGreater(MultithreadedStringTrie.Edge previous,
int keyMax,
char[] existing,
int matchesTo,
char[] key,
int keyIndex,
int keyEnd,
E value) |
protected MultithreadedStringTrie.Edge |
newEdgeLesser(MultithreadedStringTrie.Edge previous,
int keyMax,
char[] existing,
int matchesTo,
char[] key,
int keyIndex,
int keyEnd,
E value) |
protected E |
onEmpty(MultithreadedStringTrie.Edge e,
Chars keys,
int pos,
int end) |
void |
put(char[] key,
int start,
int end,
E value) |
void |
put(String key,
E value) |
protected E |
returnValue(MultithreadedStringTrie.Edge e,
Chars keys,
int pos,
int end) |
String |
toString() |
protected void |
unlock(MultithreadedStringTrie.Edge into,
boolean ownsParent) |
protected final MultithreadedStringTrie.Edge root
public void put(char[] key,
int start,
int end,
E value)
public void put(String key, E value)
put in interface PrefixedMap<E>protected void doPut(MultithreadedStringTrie.Edge into, char[] key, int index, int end, E value)
protected MultithreadedStringTrie.Edge newEdge()
protected MultithreadedStringTrie.Edge newEdge(char[] key, int index, int end, E value)
protected MultithreadedStringTrie.Edge newEdgeLesser(MultithreadedStringTrie.Edge previous, int keyMax, char[] existing, int matchesTo, char[] key, int keyIndex, int keyEnd, E value)
protected MultithreadedStringTrie.Edge newEdgeGreater(MultithreadedStringTrie.Edge previous, int keyMax, char[] existing, int matchesTo, char[] key, int keyIndex, int keyEnd, E value)
protected void lock(MultithreadedStringTrie.Edge into, boolean ownsParent)
into - - The edge to lockownsParent - - Whether we already own an explicit lock on the parent.protected void unlock(MultithreadedStringTrie.Edge into, boolean ownsParent)
into - - The edge to lockownsParent - - If true, you are already synchronized on into.cursor - - Whatever object you returned when you locked. This method
is a stub for more sophisticated subclasses of StringTrie, which may need
to perform proper concurrent locking, or event dispatch. It is called in
the finally block of whatever code ran
lock(Edge, boolean). If you use Edge
into.wait(0, nanos) in lock(), now would be a great time to call into
into.notify() :)public E get(String key)
get in interface PrefixedMap<E>public E get(char[] key)
public E get(char[] key, int pos, int end)
public Iterable<E> findPrefixed(String prefix)
findPrefixed in interface HasPrefixed<E>public void compress(CharPool charPoolTrie)
protected E returnValue(MultithreadedStringTrie.Edge e, Chars keys, int pos, int end)
protected E onEmpty(MultithreadedStringTrie.Edge e, Chars keys, int pos, int end)
Copyright © December 07, 2012–2015 The Internet Party. All rights reserved.