Class TernaryIntervalSearchTree
- All Implemented Interfaces:
PrefixMap<MutableString>
,StringMap<MutableString>
,Function<CharSequence,
,Long> Object2LongFunction<CharSequence>
,Size64
,Serializable
,Function<CharSequence,
,Long> ToLongFunction<CharSequence>
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:
-
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
ConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionboolean
add
(CharSequence s) boolean
protected long
protected LongInterval
Returns the range of strings having a given prefix.long
protected MutableString
getTerm
(long index, MutableString s) Writes a string specified by index into aMutableString
.static void
int
size()
Deprecated.long
size64()
Returns the intended number of keys in this function, or -1 if no such number exists.Methods inherited from class it.unimi.dsi.big.util.AbstractPrefixMap
list, prefixMap, rangeMap
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
defaultReturnValue, defaultReturnValue
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
andThen, andThenByte, andThenChar, andThenDouble, andThenFloat, andThenInt, andThenLong, andThenObject, andThenReference, andThenShort, applyAsLong, composeByte, composeChar, composeDouble, composeFloat, composeInt, composeLong, composeObject, composeReference, composeShort, defaultReturnValue, defaultReturnValue, get, getOrDefault, getOrDefault, put, put, remove, removeLong
-
Constructor Details
-
TernaryIntervalSearchTree
public TernaryIntervalSearchTree()Creates a new empty ternary search tree. -
TernaryIntervalSearchTree
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 Details
-
getInterval
Description copied from class:AbstractPrefixMap
Returns the range of strings having a given prefix.- Specified by:
getInterval
in classAbstractPrefixMap
- Parameters:
s
- a prefix.- Returns:
- the corresponding range of strings as an interval.
-
getApproximatedInterval
-
getTerm
Description copied from class:AbstractPrefixMap
Writes a string specified by index into aMutableString
.- Specified by:
getTerm
in classAbstractPrefixMap
- Parameters:
index
- the index of a string.s
- a mutable string.- Returns:
string
.
-
getIndex
-
containsKey
- Specified by:
containsKey
in interfaceFunction<CharSequence,
Long>
-
getLong
- Specified by:
getLong
in interfaceObject2LongFunction<CharSequence>
-
add
-
size
Deprecated.Description copied from interface:StringMap
- Specified by:
size
in interfaceFunction<CharSequence,
Long> - Specified by:
size
in interfaceSize64
- Specified by:
size
in interfaceStringMap<MutableString>
-
size64
public long size64()Description copied from interface:StringMap
Returns the intended number of keys in this function, or -1 if no such number exists.Most function implementations will have some knowledge of the intended number of keys in their domain. In some cases, however, this might not be possible. This default implementation, in particular, returns -1.
- Specified by:
size64
in interfaceSize64
- Specified by:
size64
in interfaceStringMap<MutableString>
- Returns:
- the intended number of keys in this function, or -1 if that number is not available.
-
main
-