public class TernaryIntervalSearchTree extends AbstractPrefixMap implements Serializable
Ternary search trees are a data structure used to store words over an alphabet; they are a useful alternatives to tries when the alphabet is large.
Ternary interval search trees have the additional properties of being able to locate quickly intervals of words extending a given prefix (where “quickly” means that no more successful character comparisons than the prefix length are performed). They do so by storing at each node the number of words covered by that node.
This implementation exposes a number of interfaces: in particular, the set of words is
seen as a lexicographically ordered ObjectList
.
This class is mutable, but for the time it implements only add(CharSequence)
. Words cannot
be removed.
list, prefixMap, rangeMap
Constructor and Description |
---|
TernaryIntervalSearchTree()
Creates a new empty ternary search tree.
|
TernaryIntervalSearchTree(Collection<? extends CharSequence> c)
Creates a new empty ternary search tree and populates it with a given collection of character sequences.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(CharSequence s) |
boolean |
containsKey(Object o) |
Interval |
getApproximatedInterval(CharSequence s) |
protected long |
getIndex(CharSequence s) |
protected Interval |
getInterval(CharSequence s)
Returns the range of strings having a given prefix.
|
long |
getLong(Object o) |
protected MutableString |
getTerm(int index,
MutableString s)
Writes a string specified by index into a
MutableString . |
static void |
main(String[] arg) |
int |
size() |
list, prefixMap, rangeMap
clear, defaultReturnValue, defaultReturnValue, get, put, put, remove, removeLong
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public TernaryIntervalSearchTree()
public TernaryIntervalSearchTree(Collection<? extends CharSequence> c)
c
- a collection of character sequences.protected Interval getInterval(CharSequence s)
AbstractPrefixMap
getInterval
in class AbstractPrefixMap
s
- a prefix.public Interval getApproximatedInterval(CharSequence s)
protected MutableString getTerm(int index, MutableString s)
AbstractPrefixMap
MutableString
.getTerm
in class AbstractPrefixMap
index
- the index of a string.s
- a mutable string.string
.protected long getIndex(CharSequence s)
public boolean containsKey(Object o)
containsKey
in interface it.unimi.dsi.fastutil.Function<CharSequence,Long>
public long getLong(Object o)
getLong
in interface it.unimi.dsi.fastutil.objects.Object2LongFunction<CharSequence>
public boolean add(CharSequence s)
public int size()
size
in interface it.unimi.dsi.fastutil.Function<CharSequence,Long>
public static void main(String[] arg) throws IOException, com.martiansoftware.jsap.JSAPException, NoSuchMethodException
IOException
com.martiansoftware.jsap.JSAPException
NoSuchMethodException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.