it.unimi.dsi.big.util
Class TernaryIntervalSearchTree

java.lang.Object
  extended by it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction<CharSequence>
      extended by it.unimi.dsi.big.util.AbstractPrefixMap
          extended by it.unimi.dsi.big.util.TernaryIntervalSearchTree
All Implemented Interfaces:
PrefixMap<MutableString>, StringMap<MutableString>, Function<CharSequence,Long>, Object2LongFunction<CharSequence>, Size64, Serializable

public class TernaryIntervalSearchTree
extends AbstractPrefixMap
implements Serializable

Ternary interval search trees.

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.

Since:
2.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class it.unimi.dsi.big.util.AbstractPrefixMap
list, prefixMap, rangeMap
 
Fields inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
defRetValue
 
Constructor Summary
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.
 
Method Summary
 boolean add(CharSequence s)
           
 boolean containsKey(Object o)
           
 LongInterval getApproximatedInterval(CharSequence s)
           
protected  long getIndex(CharSequence s)
           
protected  LongInterval getInterval(CharSequence s)
          Returns the range of strings having a given prefix.
 long getLong(Object o)
           
protected  MutableString getTerm(long index, MutableString s)
          Writes a string specified by index into a MutableString.
static void main(String[] arg)
           
 int size()
          Deprecated. 
 long size64()
           
 
Methods inherited from class it.unimi.dsi.big.util.AbstractPrefixMap
list, prefixMap, rangeMap
 
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
clear, defaultReturnValue, defaultReturnValue, get, put, put, remove, removeLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.fastutil.objects.Object2LongFunction
defaultReturnValue, defaultReturnValue, put, removeLong
 
Methods inherited from interface it.unimi.dsi.fastutil.Function
clear, get, put, remove
 

Constructor Detail

TernaryIntervalSearchTree

public TernaryIntervalSearchTree()
Creates a new empty ternary search tree.


TernaryIntervalSearchTree

public TernaryIntervalSearchTree(Collection<? extends CharSequence> c)
Creates a new empty ternary search tree and populates it with a given collection of character sequences.

Parameters:
c - a collection of character sequences.
Method Detail

getInterval

protected LongInterval getInterval(CharSequence s)
Description copied from class: AbstractPrefixMap
Returns the range of strings having a given prefix.

Specified by:
getInterval in class AbstractPrefixMap
Parameters:
s - a prefix.
Returns:
the corresponding range of strings as an interval.

getApproximatedInterval

public LongInterval getApproximatedInterval(CharSequence s)

getTerm

protected MutableString getTerm(long index,
                                MutableString s)
Description copied from class: AbstractPrefixMap
Writes a string specified by index into a MutableString.

Specified by:
getTerm in class AbstractPrefixMap
Parameters:
index - the index of a string.
s - a mutable string.
Returns:
string.

getIndex

protected long getIndex(CharSequence s)

containsKey

public boolean containsKey(Object o)
Specified by:
containsKey in interface Function<CharSequence,Long>

getLong

public long getLong(Object o)
Specified by:
getLong in interface Object2LongFunction<CharSequence>

add

public boolean add(CharSequence s)

size

@Deprecated
public int size()
Deprecated. 

Specified by:
size in interface Function<CharSequence,Long>
Specified by:
size in interface Size64

size64

public long size64()
Specified by:
size64 in interface Size64

main

public static void main(String[] arg)
                 throws IOException,
                        JSAPException,
                        NoSuchMethodException
Throws:
IOException
JSAPException
NoSuchMethodException