Implementation of "Purely Functional Random Access Lists" by Chris Okasaki. This gives O(1) cons and uncons, and 2 log_2 N lookup.
A consequence of the log N complexity is that naive recursion on the inner methods will (almost) never blow the stack since the depth of the structure is log N, this greatly simplifies many methods. A key example is that unlike List, using a TreeList you can sequence and traverse very large lists without blowing the stack since the stack depth is only log N.
This data-structure is useful when you want fast cons and uncons, but also want to index. It does not have an optimized concatenation.
Attributes
- Companion
- object
- Source
- TreeList.scala
- Graph
-
- Supertypes
Members list
Value members
Abstract methods
We can efficiently drop things off the front without rebuilding
We can efficiently drop things off the front without rebuilding
O(n) operation (complexity is the number of things being dropped)
Attributes
- Source
- TreeList.scala
A strict, left-to-right fold: O(N)
map to a type with a Monoid and combine in the order of the list, O(N)
map to a type with a Monoid and combine in the order of the list, O(N)
Attributes
- Source
- TreeList.scala
lookup the given index in the list.
lookup the given index in the list. O(log N). if the item is < 0 or >= size, return None
Attributes
- Source
- TreeList.scala
lookup the given index in the list.
lookup the given index in the list. O(log N). if the item is < 0 or >= size, else throw
Attributes
- Source
- TreeList.scala
The first item if nonempty
returns true if size == 0.
get the last element, if it is not empty.
get the last element, if it is not empty. O(log N) a bit more efficient than get(size - 1)
Attributes
- Source
- TreeList.scala
standard map.
standard map. O(N) operation. Since this preserves structure, it is more efficient than converting toIterator, mapping the iterator, and converting back
Attributes
- Source
- TreeList.scala
returns true if size != 0.
put an item on the front.
How many items are in this TreeList.
return the right most full binary tree on the right, the rest on left val (l, r) = items.split assert((l ++ r) == items)
return the right most full binary tree on the right, the rest on left val (l, r) = items.split assert((l ++ r) == items)
O(log N)
Attributes
- Source
- TreeList.scala
a strict, right-to-left fold.
a strict, right-to-left fold. Note, cats.Foldable defines foldRight to work on Eval, we use a different name here not to collide with the cats syntax
O(N)
Attributes
- Source
- TreeList.scala
All but the first item if nonempty
Get an iterator through the TreeList
Get an iterator through the TreeList
We can iterate through in O(N) time
Attributes
- Source
- TreeList.scala
Convert to a scala standard List.
Convert to a scala standard list, but reversed O(N)
Get a reverse iterator through the TreeList not as efficient as going in the left to right order.
Get a reverse iterator through the TreeList not as efficient as going in the left to right order.
It appears this is N log N in cost (although possible only N, as we have not proven the bound on cost)
This is useful if you only want a few things from the right, if you need to iterate the entire list, it is better to to use toListReverse which is O(N)
This is only a constant more efficient that iterating via random access using get
Attributes
- Source
- TreeList.scala
This is like headOption and tailOption in one call.
If the given index is in the list, update it, else return the current list with no change.
If the given index is in the list, update it, else return the current list with no change.
O(log N)
Attributes
- Source
- TreeList.scala
Concrete methods
Concatenate two TreeLists.
Concatenate two TreeLists. This requires doing as much work as this.size
O(this.size)
Attributes
- Source
- TreeList.scala
Attributes
- Source
- TreeList.scala
keep the elements that match a predicate O(N)
same as filter(!fn(_)) O(N)
Standard flatMap on a List type.
O(N) reversal of the treeList
Take the first n things off the list.
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
Any
- Source
- TreeList.scala
If the given index is in the list, update and return Some(updated).
If the given index is in the list, update and return Some(updated). else return None
O(log N)
Attributes
- Source
- TreeList.scala