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
Returns 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(_).
Optionally returns the first key-value pair in t that satisfies the predicate f when searching from left to right.
Optionally returns the first key-value pair in t that satisfies the predicate f when searching from right to left.
Applies 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.
Applies 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))).
Returns true if and only if all key-value pairs in t satisfy the predicate f.
Returns true if t is the empty tree.
Applies f to every key-value pair of t.
Applies 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.
Returns 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.
Returns 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 Returns 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.
Extracts 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.
Extracts k => v where k is the leftmost (i.e. smallest) key in the tree.
@Parallel Applies 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 Returns 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 Returns 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 Returns 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.
Returns the sum of all key-value pairs k => v in the tree t
according to the function f.
Returns the tree t as a list. Elements are ordered from smallest (left) to largest (right).