|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sourceforge.suggesttree.SuggestTree
public final class SuggestTree
A data structure for rank-sensitive autocompletion. It stores suggestions, each with an associated score, and provides fast access to the highest scored completions for a given prefix. Note that suggest trees are not appropriate for rankings based on the lexicographic order of the suggestions.
This implementation is not synchronized. If multiple threads access the tree concurrently, and at least one of the threads modifies the tree (by inserting/removing a suggestion or by changing the score of a suggestion), it must be synchronized externally.
| Nested Class Summary | |
|---|---|
static interface |
SuggestTree.Entry
A suggest tree entry (a suggestion and its score). |
| Constructor Summary | |
|---|---|
SuggestTree()
Creates a new, empty suggest tree. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all suggestions from the tree. |
SuggestTree.Entry |
entry(java.lang.String suggestion)
Returns the entry for the specified suggestion, or null if
the tree does not contain this suggestion. |
java.util.Iterator<SuggestTree.Entry> |
iterator()
Returns an iterator over the entries in the tree. |
void |
put(java.lang.String suggestion,
int score)
Inserts the specified suggestion with the specified score into the tree, or updates the score if the tree already contains this suggestion. |
void |
remove(java.lang.String suggestion)
Removes the specified suggestion from the tree if present. |
int |
size()
Returns the number of suggestions in the tree. |
java.util.Iterator<SuggestTree.Entry> |
suggestions(java.lang.String prefix,
int topK)
Returns an iterator over the topK highest scored entries in
the tree that start with the specified prefix. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SuggestTree()
| Method Detail |
|---|
public int size()
public void clear()
public java.util.Iterator<SuggestTree.Entry> suggestions(java.lang.String prefix,
int topK)
topK highest scored entries in
the tree that start with the specified prefix. The iterator will return
the entries in descending order of score.
If the tree is modified while an iteration is in progress, the results of the iteration are undefined.
prefix - the string to be completedtopK - the maximum number of entries to be returned by the
iterator
topK highest scored
entries in the tree that start with the specified prefix
java.lang.IllegalArgumentException - if topK is less than 1public SuggestTree.Entry entry(java.lang.String suggestion)
null if
the tree does not contain this suggestion.
suggestion - the suggestion whose entry is to be returned
null if the tree does not contain this
suggestion
public void put(java.lang.String suggestion,
int score)
suggestion - the suggestion to be inserted or newly weightedscore - the score to be associated with the suggestion
java.lang.IllegalArgumentException - if suggestion is the
empty stringpublic void remove(java.lang.String suggestion)
suggestion - the suggestion to be removed from the treepublic java.util.Iterator<SuggestTree.Entry> iterator()
iterator in interface java.lang.Iterable<SuggestTree.Entry>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||