Top Description Fields Constructors Methods
io.vavr.collection

pack-priv final Class BitMappedTrie<T>

Additional top-level classes in compilation unit: NodeModifier, LeafVisitor.

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.NoSuchElementException, java.util.function.Function, .Predicate

A `bit-mapped trie` is a very wide and shallow tree (for integer indices the depth will be `≤6`). Each node has a maximum of `32` children (configurable). Access to a given position is done by converting the index to a base 32 number and using each digit to descend down the tree. Modifying the tree is done similarly, but along the way the path is copied, returning a new root every time. `Append` inserts in the last leaf, or if the tree is full from the right, it adds another layer on top of it (the old root will be the first of the new one). `Prepend` is done similarly, but an offset is needed, because adding a new top node (where the current root would be the last node of the new root) shifts the indices by half of the current tree's full size. The `offset` shifts them back to the correct index. `Slice` is done by trimming the path from the root and discarding any `leading`/`trailing` values in effectively constant time (without memory leak, as in `Java`/`Clojure`).
Author
Pap Lőrinc

Field Summary

Modifier and TypeField and Description
private final Object
pack-priv static final int
pack-priv static final int
pack-priv static final int
private final int
private static final BitMappedTrie<?>
private final int
private final int
private static final long
pack-priv final ArrayType<T>

Constructor Summary

AccessConstructor and Description
private
BitMappedTrie(ArrayType<T> type, Object array, int offset, int length, int depthShift)

Method Summary

Modifier and TypeMethod and Description
private BitMappedTrie<T>
append(Iterator<? extends T> iterator, int size)

pack-priv BitMappedTrie<T>
appendAll(Iterable<? extends T> iterable)

private NodeModifier
appendToLeaf(Iterator<? extends T> iterator, int leafSize)

private boolean
arePointingToSameLeaf(int i, int j)

private BitMappedTrie<T>
private static <T> BitMappedTrie<T>
collapsed(ArrayType<T> type, Object array, int offset, int length, int shift)

pack-priv static int
digit(int num, int depthShift)

pack-priv BitMappedTrie<T>
drop(int n)

pack-priv static <T> BitMappedTrie<T>
pack-priv BitMappedTrie<T>
filter(Predicate<? super T> predicate)

private int
filter(Predicate<? super T> predicate, Object results, int index, T leaf, int start, int end)

pack-priv static int
firstDigit(int num, int depthShift)

pack-priv T
get(int index)

pack-priv Object
getLeaf(int index)

fetch the leaf, corresponding to the given index.

private Object
getLeafGeneral(int index)

private int
getMin(int start, int index, Object leaf)

private boolean
private boolean
pack-priv Iterator<T>
pack-priv static int
lastDigit(int num)

pack-priv int
pack-priv <U> BitMappedTrie<U>
map(Function<? super T, ? extends U> mapper)

private <U> int
map(Function<? super T, ? extends U> mapper, Object results, int index, T leaf, int start, int end)

private Object
modify(Object root, int depthShift, int index, NodeModifier node, NodeModifier leaf)

private Object
modifyNonLeaf(Object root, int depthShift, int index, NodeModifier node, NodeModifier leaf)

pack-priv static <T> BitMappedTrie<T>
ofAll(Object array)

private static <T> BitMappedTrie<T>
ofAll(Object array, ArrayType<T> type, int size)

private BitMappedTrie<T>
prepend(Iterator<? extends T> iterator, int size)

pack-priv BitMappedTrie<T>
prependAll(Iterable<? extends T> iterable)

private NodeModifier
prependToLeaf(Iterator<? extends T> iterator)

private Object
setNewNode(NodeModifier node, int previousIndex, Object array, int offset)

pack-priv BitMappedTrie<T>
take(int n)

private static int
treeSize(int branchCount, int depthShift)

pack-priv BitMappedTrie<T>
update(int index, T element)

private NodeModifier
updateLeafWith(ArrayType<T> type, T element)

pack-priv <T2> int
visit(LeafVisitor<T2> visitor)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
private final Object array
Annotations
@SuppressWarnings:serial
BRANCHING_BASEback to summary
pack-priv static final int BRANCHING_BASE
BRANCHING_FACTORback to summary
pack-priv static final int BRANCHING_FACTOR
BRANCHING_MASKback to summary
pack-priv static final int BRANCHING_MASK
depthShiftback to summary
private final int depthShift
EMPTYback to summary
private static final BitMappedTrie<?> EMPTY
lengthback to summary
private final int length
offsetback to summary
private final int offset
serialVersionUIDback to summary
private static final long serialVersionUID
typeback to summary
pack-priv final ArrayType<T> type

Constructor Detail

BitMappedTrieback to summary
private BitMappedTrie(ArrayType<T> type, Object array, int offset, int length, int depthShift)

Method Detail

appendback to summary
private BitMappedTrie<T> append(Iterator<? extends T> iterator, int size)
appendAllback to summary
pack-priv BitMappedTrie<T> appendAll(Iterable<? extends T> iterable)
appendToLeafback to summary
private NodeModifier appendToLeaf(Iterator<? extends T> iterator, int leafSize)
arePointingToSameLeafback to summary
private boolean arePointingToSameLeaf(int i, int j)
boxedback to summary
private BitMappedTrie<T> boxed()
collapsedback to summary
private static <T> BitMappedTrie<T> collapsed(ArrayType<T> type, Object array, int offset, int length, int shift)
digitback to summary
pack-priv static int digit(int num, int depthShift)
dropback to summary
pack-priv BitMappedTrie<T> drop(int n)
emptyback to summary
pack-priv static <T> BitMappedTrie<T> empty()
Annotations
@SuppressWarnings:unchecked
filterback to summary
pack-priv BitMappedTrie<T> filter(Predicate<? super T> predicate)
filterback to summary
private int filter(Predicate<? super T> predicate, Object results, int index, T leaf, int start, int end)
firstDigitback to summary
pack-priv static int firstDigit(int num, int depthShift)
getback to summary
pack-priv T get(int index)
getLeafback to summary
pack-priv Object getLeaf(int index)

fetch the leaf, corresponding to the given index. Node: the offset and length should be taken into consideration as there may be leading and trailing garbage. Also, the returned array is mutable, but should not be mutated!

Annotations
@SuppressWarnings:WeakerAccess
getLeafGeneralback to summary
private Object getLeafGeneral(int index)
getMinback to summary
private int getMin(int start, int index, Object leaf)
isFullLeftback to summary
private boolean isFullLeft()
isFullRightback to summary
private boolean isFullRight()
iteratorback to summary
pack-priv Iterator<T> iterator()
lastDigitback to summary
pack-priv static int lastDigit(int num)
lengthback to summary
pack-priv int length()
mapback to summary
pack-priv <U> BitMappedTrie<U> map(Function<? super T, ? extends U> mapper)
mapback to summary
private <U> int map(Function<? super T, ? extends U> mapper, Object results, int index, T leaf, int start, int end)
modifyback to summary
private Object modify(Object root, int depthShift, int index, NodeModifier node, NodeModifier leaf)
modifyNonLeafback to summary
private Object modifyNonLeaf(Object root, int depthShift, int index, NodeModifier node, NodeModifier leaf)
ofAllback to summary
pack-priv static <T> BitMappedTrie<T> ofAll(Object array)
ofAllback to summary
private static <T> BitMappedTrie<T> ofAll(Object array, ArrayType<T> type, int size)
prependback to summary
private BitMappedTrie<T> prepend(Iterator<? extends T> iterator, int size)
prependAllback to summary
pack-priv BitMappedTrie<T> prependAll(Iterable<? extends T> iterable)
prependToLeafback to summary
private NodeModifier prependToLeaf(Iterator<? extends T> iterator)
setNewNodeback to summary
private Object setNewNode(NodeModifier node, int previousIndex, Object array, int offset)
takeback to summary
pack-priv BitMappedTrie<T> take(int n)
treeSizeback to summary
private static int treeSize(int branchCount, int depthShift)
updateback to summary
pack-priv BitMappedTrie<T> update(int index, T element)
updateLeafWithback to summary
private NodeModifier updateLeafWith(ArrayType<T> type, T element)
visitback to summary
pack-priv <T2> int visit(LeafVisitor<T2> visitor)
Annotations
@SuppressWarnings:unchecked