RedBlackTree
enum RedBlackTree[k: Type, v: Type]Sourcecase Leafcase DoubleBlackLeafcase Node(Color, RedBlackTree[k, v], k, v, RedBlackTree[k, v])An immutable red-black tree implementation with keys
of type k and values of type v.
A red-black tree is a self-balancing binary search tree. Each node is either red or black, although a transitory color double-black is allowed during deletion. The red-black tree satisfy the following invariants.
- For all nodes with key
x, the left subtree contains only nodes with keysy<xand the right subtree contains only nodes with keysz>x. - No red node has a red parent.
- Every path from the root to a leaf contains the same number of black nodes.
Instances
instance Filterable[RedBlackTree[k]] with Order[k]Sourceinstance Traversable[RedBlackTree[k]]Sourceinstance UnorderedFoldable[RedBlackTree[k]]Sourceinstance Witherable[RedBlackTree[k]] with Order[k]SourceDefinitions
def blackHeight(t: RedBlackTree[k, v]): Int32
SourceReturns the black height of t.
def empty(): RedBlackTree[k, v]
SourceReturns the empty tree.
def exists(f: k -> (v -> Bool \ ef), t: RedBlackTree[k, v]): Bool \ ef
SourceReturns true if and only if at least one key-value pair in t satisfies the predicate f.
Returns false if t is the empty tree.
Returns a new copy of tree t with just the nodes that satisfy the predicate f.
def filterMap(f: a -> Option[b] \ ef, t: RedBlackTree[k, a]): RedBlackTree[k, b] \ ef with Order[k]
SourceCollects the results of applying the partial function f to every element in t.
This traverses tree t and produces a new tree with just nodes where applying f
produces Some(_).
def findLeft(f: k -> (v -> Bool \ ef), t: RedBlackTree[k, v]): Option[(k, v)] \ ef
SourceOptionally returns the first key-value pair in t that satisfies the predicate f when searching from left to right.
def findRight(f: k -> (v -> Bool \ ef), t: RedBlackTree[k, v]): Option[(k, v)] \ ef
SourceOptionally returns the first key-value pair in t that satisfies the predicate f when searching from right to left.
def foldLeft(f: b -> (k -> (v -> b \ ef)), s: b, t: RedBlackTree[k, v]): b \ ef
SourceApplies f to a start value s and all key-value pairs in t going from left to right.
That is, the result is of the form: f(...f(f(s, k1, v1), k2, v2)..., vn).
Returns the result of mapping each key-value pair and combining the results.
def foldRight(f: k -> (v -> (b -> b \ ef)), s: b, t: RedBlackTree[k, v]): b \ ef
SourceApplies f to a start value s and all key-value pairs in tree going from right to left.
That is, the result is of the form: f(k1, v1, ...f(kn-1, vn-1, f(kn, vn, s))).
def forAll(f: k -> (v -> Bool \ ef), t: RedBlackTree[k, v]): Bool \ ef
SourceReturns true if and only if all key-value pairs in t satisfy the predicate f.
Returns true if t is the empty tree.
def forEach(f: k -> (v -> Unit \ ef), t: RedBlackTree[k, v]): Unit \ ef
SourceApplies f to every key-value pair of t.
def forEachWithIndex(f: Int32 -> (k -> (v -> Unit \ ef)), t: RedBlackTree[k, v]): Unit \ ef
SourceApplies f to every key-value pair of t along with that element's index.
Returns Some(v) if k => v is in t.
Otherwise returns None.
Updates t with k => v if k => v1 is in t.
Otherwise, updates t with k => v.
def insertWith(f: k -> (v -> (v -> v \ ef)), k: k, v: v, t: RedBlackTree[k, v]): RedBlackTree[k, v] \ ef with Order[k]
SourceUpdates t with k => f(k, v, v1) if k => v1 is in t.
Otherwise, updates t with k => v.
def isEmpty(t: RedBlackTree[k, v]): Bool
SourceReturns true if and only if t is the empty tree.
def iterator(rc: Region[r], t: RedBlackTree[k, v]): Iterator[(k, v), r, r] \ r
SourceReturns an iterator over t.
Returns the concatenation of the string representation of each key k
in t with sep inserted between each element.
Returns the concatenation of the string representation of each value v
in t with sep inserted between each element.
def joinWith(f: k -> (v -> String \ ef), sep: String, t: RedBlackTree[k, v]): String \ ef
SourceReturns the concatenation of the string representation of each key-value pair
k => v in t according to f with sep inserted between each element.
def mapAWithKey(f: k -> (v1 -> m[v2] \ ef), t: RedBlackTree[k, v1]): m[RedBlackTree[k, v2]] \ ef with Applicative[m]
SourceReturns a RedBlackTree with mappings k => f(v) for every k => v in t.
@ParallelWhenPure def mapWithKey(f: k -> (v1 -> v2 \ ef), t: RedBlackTree[k, v1]): RedBlackTree[k, v2] \ ef
SourceReturns a RedBlackTree with mappings k => f(k, v) for every k => v in t.
Purity reflective: Runs in parallel when given a pure function f.
def maximumKey(t: RedBlackTree[k, v]): Option[(k, v)]
SourceExtracts k => v where k is the rightmost (i.e. largest) key in the tree.
Returns true if and only if t contains the key k.
def minimumKey(t: RedBlackTree[k, v]): Option[(k, v)]
SourceExtracts k => v where k is the leftmost (i.e. smallest) key in the tree.
def nonEmpty(t: RedBlackTree[k, v]): Bool
SourceReturns true if and only if t is a non-empty tree.
@Parallel def parCount(f: k -> (v -> Bool), t: RedBlackTree[k, v]): Int32
SourceApplies f over the tree t in parallel and returns the number of elements
that satisfy the predicate f.
The implementation spawns a number of threads each applying f sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
@Parallel def parExists(f: k -> (v -> Bool), t: RedBlackTree[k, v]): Bool
SourceReturns true if and only if at least one key-value pair in t satisfies the predicate f.
Returns false if t is the empty tree.
The function f must be pure.
Traverses the tree t in parallel.
@Parallel def parForAll(f: k -> (v -> Bool), t: RedBlackTree[k, v]): Bool
SourceReturns true if and only if all key-value pairs in t satisfy the predicate f.
Returns true if t is the empty tree.
The function f must be pure.
Traverses the tree t in parallel.
@Parallel def parMaximumBy(cmp: k -> (v -> (k -> (v -> Comparison))), t: RedBlackTree[k, v]): Option[(k, v)]
SourceApplies cmp over the tree t in parallel and optionally returns the largest
element according to cmp.
The implementation spawns a number of threads each applying cmp sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
@Parallel def parMinimumBy(cmp: k -> (v -> (k -> (v -> Comparison))), t: RedBlackTree[k, v]): Option[(k, v)]
SourceApplies cmp over the tree t in parallel and optionally returns the lowest
element according to cmp.
The implementation spawns a number of threads each applying cmp sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
@Parallel def parSumWith(f: k -> (v -> Int32), t: RedBlackTree[k, v]): Int32
SourceReturns the sum of all key-value pairs k => v in the tree t
according to the function f.
The implementation spawns a number of threads each applying f sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
def rangeQuery(p: k -> Comparison \ ef1, f: k -> (v -> a \ ef2), t: RedBlackTree[k, v]): List[a] \ ef1 + ef2
SourceExtracts a range of key-value pairs from t.
That is, the result is a list of all pairs f(k, v) where p(k) returns Equal.
def rangeQueryWith(p: k -> Comparison \ ef1, f: k -> (v -> Unit \ ef2), t: RedBlackTree[k, v]): Unit \ ef1 + ef2
SourceApplies f to all key-value pairs from t where p(k) returns Comparison.EqualTo.
The function f must be impure.
def reduceLeft(f: k -> (v -> (k -> (v -> (k, v) \ ef))), t: RedBlackTree[k, v]): Option[(k, v)] \ ef
SourceApplies f to all key-value pairs in tree going from left to right until a single pair (k, v) is obtained.
That is, the result is of the form: Some(f(...f(f(k1, v1, k2, v2), k3, v3)..., kn, vn))
Returns None if t is the empty tree.
def reduceRight(f: k -> (v -> (k -> (v -> (k, v) \ ef))), t: RedBlackTree[k, v]): Option[(k, v)] \ ef
SourceApplies f to all key-value pairs in t going from right to left until a single pair (k, v) is obtained.
That is, the result is of the form: Some(f(k1, v1, ...f(kn-2, vn-2, f(kn-1, vn-1, kn, vn))...)).
Returns None if t is the empty tree.
Removes k => v from t if t contains the key k.
Otherwise, returns t.
def size(t: RedBlackTree[k, v]): Int32
SourceReturns the number of nodes in t.
def sumKeys(t: RedBlackTree[Int32, v]): Int32
SourceReturns the sum of all keys in the tree t.
def sumValues(t: RedBlackTree[k, Int32]): Int32
SourceReturns the sum of all values in the tree t.
def sumWith(f: k -> (v -> Int32 \ ef), t: RedBlackTree[k, v]): Int32 \ ef
SourceReturns the sum of all key-value pairs k => v in the tree t
according to the function f.
def toList(t: RedBlackTree[k, v]): List[(k, v)]
SourceReturns the tree t as a list. Elements are ordered from smallest (left) to largest (right).