StringHashTrie
com.jsmacrosce.StringHashTrie
Stores strings in a prefix trie and provides collection operations and prefix searches.
Constructors
new StringHashTrie
new StringHashTrie()#Initializes an empty root trie with no parent.
Methods
add
Adds a case-sensitive string if it is not already stored. A null string causes NullPointerException.
Parameters:
s: string to add
Returns:
true if the string was added; false if it was already presentaddAll
addAll(Collection<? extends String> c): boolean#Adds each string in the collection. Processing is not rolled back if an element fails; a null collection or null element causes NullPointerException.
Parameters:
c: strings to add
Returns:
true if at least one string was addedAdds each supplied string. Processing is not rolled back if an element fails; a null array or null element causes NullPointerException.
Parameters:
o: strings to add
Returns:
true if at least one string was addedclear
clear(): void#Removes all strings stored directly or below this trie node.
contains
containsAll
containsAll(Collection<?> c): boolean#Tests whether every element of the collection is a stored string. Non-strings and
null elements are not contained; a null collection causes NullPointerException.Parameters:
c: collection of values to test
Returns:
true if every element is contained, including when the collection is emptyTests whether every supplied string is stored; unlike the collection overload, this accepts an array of strings. Null elements are not contained; a null array causes NullPointerException.
Parameters:
o: strings to test
Returns:
true if every string is contained, including when the array is emptygetAll
getAllWithPrefix
Searches for strings beginning with the given case-sensitive prefix. When the prefix ends within a trie key, this returns the first matching leaf if present; otherwise, it returns the first matching child subtree, so other matches may be omitted.
Parameters:
prefix: prefix to match
Returns: matching strings, or all strings when
prefix is emptygetAllWithPrefixCaseInsensitive
Searches for strings beginning with the given prefix, ignoring case. When the prefix is longer than a trie key, matching is performed segment by segment, which may omit matches when case-insensitive comparison changes length.
Parameters:
prefix: prefix to match
Returns: matching strings, or all strings when
prefix is emptyisEmpty
isEmpty(): boolean#Returns whether this node has no directly stored strings and no children.
Returns:
true when this node has neither leaves nor childreniterator
remove
removeAll
removeAll(Collection<?> c): boolean#Removes each supplied element that is a string in this trie. The collection must not be
null; otherwise this method throws NullPointerException.Parameters:
c: non-null collection of elements to remove; non-strings and null elements are ignored
Returns:
true if at least one string was removedretainAll
retainAll(Collection<?> c): boolean#Removes every stored string not contained in the supplied collection. The collection must not be
null; otherwise this method throws NullPointerException.Parameters:
c: non-null collection of strings to retain
Returns:
true if at least one string was removedsize
size(): int#Returns the number of strings stored in this trie, including strings in descendant nodes.
Returns: the total stored string count
toArray
Returns the strings currently stored in this trie as a new array; its order is unspecified.
Returns: a new array containing the current strings
toArray(T[] a): T[]#Copies the strings currently stored in this trie into an array, following
Set.toArray(T[]) semantics. The result is a snapshot with unspecified element order. If a is too small, a new array of the same runtime type is returned; if it is larger, the first unused element is set to null. A null array causes NullPointerException, and an incompatible component type causes ArrayStoreException.Parameters:
a: destination array
Type Parameters:
T: the array element type
Returns: the destination array if large enough, otherwise a new array of the same runtime type
toArray(IntFunction<T[]> arg0): T[]#Returns: T[]