Package crawlercommons.domains
Class SuffixTrie<V>
- java.lang.Object
-
- crawlercommons.domains.SuffixTrie<V>
-
public class SuffixTrie<V> extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SuffixTrie.LookupResult<V>
Wrapper for results when a string is checked for suffixes contained in the suffix trie.protected static class
SuffixTrie.Node<V>
-
Field Summary
Fields Modifier and Type Field Description protected SuffixTrie.Node<V>
root
-
Constructor Summary
Constructors Constructor Description SuffixTrie()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(String suffix)
Checks whether trie contains a suffix string.V
get(String suffix)
Get value associated with suffix string in trie.protected SuffixTrie.LookupResult<V>
getLongestSuffix(String string)
Match the longest suffix of a string contained in trie.protected List<SuffixTrie.LookupResult<V>>
getSuffixes(String string)
Match all suffixes of a string contained in trie.V
put(String suffix, V value)
Insert a string and an associated value into the trie.
-
-
-
Field Detail
-
root
protected SuffixTrie.Node<V> root
-
-
Method Detail
-
put
public V put(String suffix, V value)
Insert a string and an associated value into the trie. If the string is already present in the trie, the existing value is replaced by the new value.- Parameters:
suffix
- suffix string inserted into trievalue
- value associated with string- Returns:
- previous value associated with string or null if there was no previous value
-
get
public V get(String suffix)
Get value associated with suffix string in trie.- Parameters:
suffix
- suffix string searched in trie- Returns:
- value if suffix is found in trie, null otherwise
-
contains
public boolean contains(String suffix)
Checks whether trie contains a suffix string.- Parameters:
suffix
- suffix string searched in trie- Returns:
- true if suffix is found in trie
-
getLongestSuffix
protected SuffixTrie.LookupResult<V> getLongestSuffix(String string)
Match the longest suffix of a string contained in trie.- Parameters:
string
- to be checked for a contained (longest) suffix- Returns:
- lookup result or null if no suffix is found
-
getSuffixes
protected List<SuffixTrie.LookupResult<V>> getSuffixes(String string)
Match all suffixes of a string contained in trie.- Parameters:
string
- string to be checked for suffixes contained in trie- Returns:
- list of suffix lookup results, from shortest to longest
-
-