Package org.organicdesign.fp.collections
Class RrbTree.MutRrbt<E>
- java.lang.Object
-
- org.organicdesign.fp.collections.RrbTree<E>
-
- org.organicdesign.fp.collections.RrbTree.MutRrbt<E>
-
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,BaseList<E>,MutList<E>,Sized,UnmodCollection<E>,UnmodIterable<E>,UnmodList<E>,UnmodSortedCollection<E>,UnmodSortedIterable<E>,Indented,Transformable<E>
public static class RrbTree.MutRrbt<E> extends RrbTree<E> implements MutList<E>
Mutable version of anRrbTree. Timing information is available there.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.organicdesign.fp.collections.RrbTree
RrbTree.ImRrbt<E>, RrbTree.MutRrbt<E>
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodIterable
UnmodIterable.UnIterable
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodList
UnmodList.AbstractUnmodList<E>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull RrbTree.MutRrbt<E>append(E val)Returns a new BaseList with the additional item at the end.@NotNull RrbTree.MutRrbt<E>appendSome(@NotNull Fn0<? extends @NotNull Option<E>> supplier)If supplier returns Some, return a new BaseList with the additional item at the end.@NotNull RrbTree.MutRrbt<E>concat(@Nullable Iterable<? extends E> es)Efficiently adds items to the end of this ImList.Eget(int i)@NotNull RrbTree.ImRrbt<E>immutable()Returns an immutable version of this mutable list.@NotNull StringindentedStr(int indent)Returns a string where line breaks extend the given amount of indentation.@NotNull RrbTree.MutRrbt<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.@NotNull UnmodSortedIterator<E>iterator()A convenience method to get a listIterator.@NotNull RrbTree.MutRrbt<E>join(@NotNull 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.protected @NotNull RrbTree.MutRrbt<E>makeNew(E @NotNull [] f, int fi, int fl, @NotNull org.organicdesign.fp.collections.RrbTree.Node<E> r, int s)Allows removing duplicated code by letting super-class produce new members of subclass types.protected @NotNull RrbTree.MutRrbt<E>mt()Creates a new empty ("M-T") tree of the appropriate (mutable/immutable) type.@NotNull RrbTree.MutRrbt<E>precat(@Nullable Iterable<? extends E> es)Add items to the beginning of this Transformable ("precat" is a PREpending version of conCAT).@NotNull RrbTree.MutRrbt<E>replace(int index, E item)Replace the item at the given index.intsize()Returns the number of items in this collection or iterable.@NotNull Tuple2<RrbTree.MutRrbt<E>,RrbTree.MutRrbt<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.@NotNull StringtoString()@NotNull RrbTree.MutRrbt<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).-
Methods inherited from class org.organicdesign.fp.collections.RrbTree
empty, emptyMutable, equals, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, spliterator
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
Methods inherited from interface org.organicdesign.fp.collections.UnmodIterable
drop, dropWhile, filter, flatMap, fold, foldUntil, map, take, takeWhile, whereNonNull
-
Methods inherited from interface org.organicdesign.fp.collections.UnmodList
add, addAll, clear, contains, containsAll, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, sort, subList, toArray, toArray
-
-
-
-
Method Detail
-
makeNew
@NotNull protected @NotNull RrbTree.MutRrbt<E> makeNew(E @NotNull [] f, int fi, int fl, @NotNull @NotNull org.organicdesign.fp.collections.RrbTree.Node<E> r, int s)
Description copied from class:RrbTreeAllows removing duplicated code by letting super-class produce new members of subclass types.
-
append
@Contract(mutates="this") @NotNull public @NotNull RrbTree.MutRrbt<E> append(E val)
Returns a new BaseList with the additional item at the end.
-
appendSome
@Contract(mutates="this") @NotNull public @NotNull RrbTree.MutRrbt<E> appendSome(@NotNull @NotNull Fn0<? extends @NotNull Option<E>> supplier)
If supplier returns Some, return a new BaseList with the additional item at the end. If None, just return this BaseList unmodified.- Specified by:
appendSomein interfaceBaseList<E>- Specified by:
appendSomein interfaceMutList<E>- Specified by:
appendSomein classRrbTree<E>- Parameters:
supplier- returnOption.Someto append,Nonefor a no-op.
-
concat
@Contract(mutates="this") @NotNull public @NotNull RrbTree.MutRrbt<E> concat(@Nullable @Nullable Iterable<? extends E> es)
Efficiently adds items to the end of this ImList.
-
precat
@Contract(mutates="this") @NotNull public @NotNull RrbTree.MutRrbt<E> precat(@Nullable @Nullable Iterable<? extends E> es)
Add items to the beginning of this Transformable ("precat" is a PREpending version of conCAT). Precat is implemented here because it is a very cheap operation on an RRB-Tree. It's not implemented on PersistentVector because it is very expensive there.- Specified by:
precatin interfaceTransformable<E>- Specified by:
precatin interfaceUnmodIterable<E>- Specified by:
precatin classRrbTree<E>- Parameters:
es- the items to add- Returns:
- a new Transformable with the items added.
-
get
public E get(int i)
-
immutable
@NotNull public @NotNull RrbTree.ImRrbt<E> immutable()
Returns an immutable version of this mutable list.
-
indentedStr
@NotNull public @NotNull String indentedStr(int indent)
Returns a string where line breaks extend the given amount of indentation.- Specified by:
indentedStrin interfaceIndented- Specified by:
indentedStrin classRrbTree<E>- Parameters:
indent- the amount of indent to start at. Pretty-printed subsequent lines may have additional indent.- Returns:
- a string with the given starting offset (in spaces) for every line.
-
insert
@Contract(mutates="this") @NotNull public @NotNull RrbTree.MutRrbt<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.
-
iterator
@NotNull public @NotNull UnmodSortedIterator<E> iterator()
A convenience method to get a listIterator.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceList<E>- Specified by:
iteratorin interfaceUnmodCollection<E>- Specified by:
iteratorin interfaceUnmodIterable<E>- Specified by:
iteratorin interfaceUnmodList<E>- Specified by:
iteratorin interfaceUnmodSortedCollection<E>- Specified by:
iteratorin interfaceUnmodSortedIterable<E>- Specified by:
iteratorin classRrbTree<E>
-
join
@NotNull public @NotNull RrbTree.MutRrbt<E> join(@NotNull @NotNull 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.
-
replace
@Contract(mutates="this") @NotNull public @NotNull RrbTree.MutRrbt<E> replace(int index, E item)
Replace the item at the given index. Note: i.replace(i.size(), o) used to be equivalent to i.concat(o), but it probably won't be for the RRB tree implementation, so this will change too.
-
without
@NotNull public @NotNull RrbTree.MutRrbt<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).
-
size
public int size()
Description copied from class:RrbTreeReturns the number of items in this collection or iterable.
-
mt
@NotNull protected @NotNull RrbTree.MutRrbt<E> mt()
Description copied from class:RrbTreeCreates a new empty ("M-T") tree of the appropriate (mutable/immutable) type.
-
split
@NotNull public @NotNull Tuple2<RrbTree.MutRrbt<E>,RrbTree.MutRrbt<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.
-
-