public abstract class RrbTree<E> extends Object implements BaseList<E>, Indented
An RRB Tree is an immutable List (like Clojure's PersistentVector) that also supports random inserts, deletes, and can be split and joined back together in logarithmic time. This is based on the paper, "RRB-Trees: Efficient Immutable Vectors" by Phil Bagwell and Tiark Rompf, with the following differences:
Details were filled in from the Cormen, Leiserson, Rivest & Stein Algorithms book entry on B-Trees. Also with an awareness of the Clojure PersistentVector by Rich Hickey. All errors are by Glen Peterson.
Compared to other collections (timings summary from 2017-06-11):
RrbTree.ImRrbt
varies between 90% and 100% of the speed of PersistentVector
(biggest difference above 100K).
RrbTree.MutableRrbt
varies between 45% and 80% of the speed of
PersistentVector.MutableVector
(biggest difference from 100 to 1M).Latest detailed timing results are here.
Modifier and Type | Class and Description |
---|---|
static class |
RrbTree.ImRrbt<E>
Immutable version of an
RrbTree . |
static class |
RrbTree.MutableRrbt<E>
Mutable version of an
RrbTree . |
UnmodList.AbstractUnmodList<E>
Constructor and Description |
---|
RrbTree() |
Modifier and Type | Method and Description |
---|---|
abstract RrbTree<E> |
append(E t)
Adds one item to the end of the ImList.
|
static <T> RrbTree.ImRrbt<T> |
empty()
Returns the empty, immutable RRB-Tree (there is only one)
|
static <T> RrbTree.MutableRrbt<T> |
emptyMutable()
Returns the empty, mutable RRB-Tree (there is only one)
|
boolean |
equals(Object other) |
abstract E |
get(int i) |
int |
hashCode()
This implementation is correct and compatible with java.util.AbstractList, but O(n).
|
abstract String |
indentedStr(int indent)
Returns a string where line breaks extend the given amount of indentation.
|
abstract RrbTree<E> |
insert(int idx,
E element)
Inserts an item in the RRB tree pushing the current element at that index and all subsequent
elements to the right.
|
abstract UnmodSortedIterator<E> |
iterator()
A convenience method to get a listIterator.
|
abstract RrbTree<E> |
join(RrbTree<E> that)
Joins the given tree to the right side of this tree (or this to the left side of that one) in
something like O(log n) time.
|
abstract RrbTree<E> |
replace(int index,
E item)
Replace the item at the given index.
|
abstract int |
size()
Returns the number of items in this collection or iterable.
|
abstract Tuple2<? extends RrbTree<E>,? extends RrbTree<E>> |
split(int splitIndex)
Divides this RRB-Tree such that every index less-than the given index ends up in the left-hand
tree and the indexed item and all subsequent ones end up in the right-hand tree.
|
RrbTree<E> |
without(int index)
Returns a new RrbTree minus the given item (all items to the right are shifted left one)
This is O(log n).
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
concat, get, head, reverse
add, add, addAll, addAll, clear, contains, containsAll, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, permutations, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, sort, subList, toArray, toArray
spliterator
parallelStream, stream
castFromList, castFromSortedMap, castFromSortedSet, equal
drop, dropWhile, filter, flatMap, fold, foldUntil, hash, map, precat, take, takeWhile, toString
toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableRrbt, toMutableSet, toMutableSortedMap, toMutableSortedSet
public static <T> RrbTree.ImRrbt<T> empty()
public static <T> RrbTree.MutableRrbt<T> emptyMutable()
public abstract RrbTree<E> insert(int idx, E element)
idx
- the insertion pointelement
- the item to insertpublic abstract UnmodSortedIterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface List<E>
iterator
in interface UnmodCollection<E>
iterator
in interface UnmodIterable<E>
iterator
in interface UnmodList<E>
iterator
in interface UnmodSortedCollection<E>
iterator
in interface UnmodSortedIterable<E>
public abstract RrbTree<E> join(RrbTree<E> that)
public abstract RrbTree<E> replace(int index, E item)
public abstract int size()
public abstract Tuple2<? extends RrbTree<E>,? extends RrbTree<E>> split(int splitIndex)
splitIndex
- the split point (excluded from the left-tree, included in the right one)public RrbTree<E> without(int index)
public boolean equals(Object other)
public int hashCode()
public abstract String indentedStr(int indent)
indentedStr
in interface Indented
indent
- the amount of indent to start at. Pretty-printed subsequent lines may have
additional indent.Copyright © 2018. All rights reserved.