Package autocomplete
Class TernarySearchTreeAutocomplete
- java.lang.Object
-
- autocomplete.TernarySearchTreeAutocomplete
-
- All Implemented Interfaces:
Autocomplete
public class TernarySearchTreeAutocomplete extends Object implements Autocomplete
Ternary search tree (TST) implementation of theAutocomplete
interface.- See Also:
Autocomplete
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TernarySearchTreeAutocomplete.Node
A search tree node representing a single character in an autocompletion term.
-
Field Summary
Fields Modifier and Type Field Description private TernarySearchTreeAutocomplete.Node
overallRoot
The overall root of the tree: the first character of the first autocompletion term added to this tree.
-
Constructor Summary
Constructors Constructor Description TernarySearchTreeAutocomplete()
Constructs an empty instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private TernarySearchTreeAutocomplete.Node
add(TernarySearchTreeAutocomplete.Node root, CharSequence term, int index)
void
addAll(Collection<? extends CharSequence> terms)
Adds the given collection of autocompletion terms.List<CharSequence>
allMatches(CharSequence prefix)
Returns all autocompletion terms that match the given prefix.private void
collect(TernarySearchTreeAutocomplete.Node root, StringBuilder prefix, List<CharSequence> result)
private TernarySearchTreeAutocomplete.Node
get(TernarySearchTreeAutocomplete.Node root, CharSequence term, int index)
-
-
-
Field Detail
-
overallRoot
private TernarySearchTreeAutocomplete.Node overallRoot
The overall root of the tree: the first character of the first autocompletion term added to this tree.
-
-
Method Detail
-
addAll
public void addAll(Collection<? extends CharSequence> terms)
Description copied from interface:Autocomplete
Adds the given collection of autocompletion terms.- Specified by:
addAll
in interfaceAutocomplete
- Parameters:
terms
- collection containing elements to be added.
-
add
private TernarySearchTreeAutocomplete.Node add(TernarySearchTreeAutocomplete.Node root, CharSequence term, int index)
-
get
private TernarySearchTreeAutocomplete.Node get(TernarySearchTreeAutocomplete.Node root, CharSequence term, int index)
-
allMatches
public List<CharSequence> allMatches(CharSequence prefix)
Description copied from interface:Autocomplete
Returns all autocompletion terms that match the given prefix.- Specified by:
allMatches
in interfaceAutocomplete
- Parameters:
prefix
- search query.
-
collect
private void collect(TernarySearchTreeAutocomplete.Node root, StringBuilder prefix, List<CharSequence> result)
-
-