public class ImmutableBinaryTrie<T> extends it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction<T> implements Serializable
Instance of this class are built starting from a lexicographically ordered
list of BitVector
s representing binary words. Each word
is assigned its position (starting from 0) in the list. The words are then organised in a
binary trie with path compression.
Once the trie has been built, it is possible to ask whether a word w is contained in the trie (getting back its position in the list), the interval given by the words extending w and the approximated interval defined by w.
Modifier and Type | Class and Description |
---|---|
protected static class |
ImmutableBinaryTrie.Node
A node in the trie.
|
Modifier and Type | Field and Description |
---|---|
protected ImmutableBinaryTrie.Node |
root
The root of the trie.
|
static long |
serialVersionUID |
Constructor and Description |
---|
ImmutableBinaryTrie(Iterable<? extends T> elements,
TransformationStrategy<? super T> transformationStrategy)
Creates a trie from a set of elements.
|
Modifier and Type | Method and Description |
---|---|
protected ImmutableBinaryTrie.Node |
buildTrie(it.unimi.dsi.fastutil.objects.ObjectList<LongArrayBitVector> elements,
int pos)
Builds a trie recursively.
|
boolean |
containsKey(Object element) |
int |
get(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
Return the index of the word returned by the given iterator, or -1 if the word is not this trie.
|
Interval |
getApproximatedInterval(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
Returns an approximated prefix interval around the word returned by the specified iterator.
|
Interval |
getApproximatedInterval(T element)
Returns an approximated interval around the specified word.
|
long |
getIndex(Object element) |
Interval |
getInterval(BitVector word)
Returns an interval given by the smallest and the largest word in the trie starting with the specified word.
|
Interval |
getInterval(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
Returns an interval given by the smallest and the largest word in the trie starting with
the word returned by the given iterator.
|
long |
getLong(Object element) |
int |
size()
Returns the number of binary words in this trie.
|
String |
toString() |
public static final long serialVersionUID
protected final ImmutableBinaryTrie.Node root
public ImmutableBinaryTrie(Iterable<? extends T> elements, TransformationStrategy<? super T> transformationStrategy)
elements
- a set of elementstransformationStrategy
- a transformation strategy that must turn elements
into a list of
distinct, lexicographically increasing (in iteration order) binary words.protected ImmutableBinaryTrie.Node buildTrie(it.unimi.dsi.fastutil.objects.ObjectList<LongArrayBitVector> elements, int pos)
The trie will contain the suffixes of words in words
starting at pos
.
elements
- a list of elements.pos
- a starting position.words
starting at pos
.public int size()
public long getIndex(Object element)
public long getLong(Object element)
getLong
in interface it.unimi.dsi.fastutil.objects.Object2LongFunction<T>
public boolean containsKey(Object element)
public int get(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
iterator
- a boolean iterator that will be used to find a word in this trie.getLong(Object)
public Interval getInterval(BitVector word)
word
- a word.word
(thus, the empty inteval
if no such words exist).getInterval(BooleanIterator)
public Interval getInterval(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
iterator
- an iterator.iterator
(thus, the empty inteval
if no such words exist).getInterval(BitVector)
public Interval getApproximatedInterval(T element)
Given a word w, the corresponding approximated interval is defined as follows: if the words in the approximator are thought of as left interval extremes in a larger lexicographically ordered set of words, and we number these word intervals using the indices of their left extremes, then the first word extending w would be in the word interval given by the left extreme of the interval returned by this method, whereas the last word extending w would be in the word interval given by the right extreme of the interval returned by this method. If no word in the larger set could possibly extend w (because w is smaller than the lexicographically smallest word in the approximator) the result is just an empty interval.
element
- an element.getApproximatedInterval(BooleanIterator)
public Interval getApproximatedInterval(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
iterator
- an iterator.word
would be in the word interval given by
the left extreme of the Interval
returned by this method, whereas
the last word extending word
would be in the word
interval given by the right extreme of the Interval
returned by this method.getApproximatedInterval(Object)
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.