RedBlackTree
Enums
Definitions
def
blackHeight
[kv]
(
t :
RedBlackTree[k, v]
)
: Int32
\ Pure
Returns the black height of t.
def
empty
[kv]
: RedBlackTree[k, v]
\ Pure
Returns the empty tree.
def
exists
[kvef]
(
f :
k -> (v -> Bool \ ef)
t :
RedBlackTree[k, v]
)
: Bool
\ ef
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.
def
filter
[vefk]
(
f :
v -> Bool \ ef
t :
RedBlackTree[k, v]
)
: RedBlackTree[k, v]
\ ef
with
Order[k]
Returns a new copy of tree t with just the nodes that satisfy the predicate f.
def
filterMap
[aefbk]
(
f :
a -> Option[b] \ ef
t :
RedBlackTree[k, a]
)
: RedBlackTree[k, b]
\ ef
with
Order[k]
Collects 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
[kvef]
(
f :
k -> (v -> Bool \ ef)
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ ef
Optionally returns the first key-value pair in t that satisfies the predicate f when searching from left to right.
def
findRight
[kvef]
(
f :
k -> (v -> Bool \ ef)
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ ef
Optionally returns the first key-value pair in t that satisfies the predicate f when searching from right to left.
def
foldLeft
[bkvef]
(
f :
b -> (k -> (v -> b \ ef))
s :
b
t :
RedBlackTree[k, v]
)
: b
\ ef
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).
def
foldMap
[kvefb]
(
f :
k -> (v -> b \ ef)
t :
RedBlackTree[k, v]
)
: b
\ ef
with
Monoid[b]
Returns the result of mapping each key-value pair and combining the results.
def
foldRight
[kvbef]
(
f :
k -> (v -> (b -> b \ ef))
s :
b
t :
RedBlackTree[k, v]
)
: b
\ ef
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))).
def
foldRightWithCont
[kvefb]
(
f :
k -> (v -> ((Unit -> b \ ef) -> b \ ef))
z :
b
t :
RedBlackTree[k, v]
)
: b
\ ef
Applies f to a start value z and all key-value pairs in t 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))).
A foldRightWithCont allows early termination by not calling the continuation.
def
forAll
[kvef]
(
f :
k -> (v -> Bool \ ef)
t :
RedBlackTree[k, v]
)
: Bool
\ ef
Returns 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
[kvef]
(
f :
k -> (v -> Unit \ ef)
t :
RedBlackTree[k, v]
)
: Unit
\ ef
Applies f to every key-value pair of t.
def
forEachWithIndex
[kvef]
(
f :
Int32 -> (k -> (v -> Unit \ ef))
t :
RedBlackTree[k, v]
)
: Unit
\ ef
Applies f to every key-value pair of t along with that element's index.
def
get
[kv]
(
k :
k
t :
RedBlackTree[k, v]
)
: Option[v]
\ Pure
with
Order[k]
Returns Some(v) if k => v is in t.
Otherwise returns None.
def
insert
[kv]
(
k :
k
v :
v
t :
RedBlackTree[k, v]
)
: RedBlackTree[k, v]
\ Pure
with
Order[k]
Updates t with k => v if k => v1 is in t.
Otherwise, updates t with k => v.
def
insertWith
[kvef]
(
f :
k -> (v -> (v -> v \ ef))
k :
k
v :
v
t :
RedBlackTree[k, v]
)
: RedBlackTree[k, v]
\ ef
with
Order[k]
Updates t with k => f(k, v, v1) if k => v1 is in t.
Otherwise, updates t with k => v.
def
isEmpty
[kv]
(
t :
RedBlackTree[k, v]
)
: Bool
\ Pure
Returns true if and only if t is the empty tree.
def
iterator
[rkv]
(
rc :
Region[r]
t :
RedBlackTree[k, v]
)
: Iterator[(k, v), r, r]
\ r
Returns an iterator over t.
def
joinKeys
[kv]
(
sep :
String
t :
RedBlackTree[k, v]
)
: String
\ Pure
with
ToString[k]
Returns the concatenation of the string representation of each key k
in t with sep inserted between each element.
def
joinValues
[kv]
(
sep :
String
t :
RedBlackTree[k, v]
)
: String
\ Pure
with
ToString[v]
Returns the concatenation of the string representation of each value v
in t with sep inserted between each element.
def
joinWith
[kvef]
(
f :
k -> (v -> String \ ef)
sep :
String
t :
RedBlackTree[k, v]
)
: String
\ ef
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
[kv1efmv2]
(
f :
k -> (v1 -> m[v2] \ ef)
t :
RedBlackTree[k, v1]
)
: m[RedBlackTree[k, v2]]
\ ef
with
Applicative[m]
Returns a RedBlackTree with mappings k => f(v) for every k => v in t.
def
mapWithKey
[kv1efv2]
(
f :
k -> (v1 -> v2 \ ef)
t :
RedBlackTree[k, v1]
)
: RedBlackTree[k, v2]
\ ef
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.
def
maximumKey
[kv]
(
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ Pure
Extracts k => v where k is the rightmost (i.e. largest) key in the tree.
def
memberOf
[kv]
(
k :
k
t :
RedBlackTree[k, v]
)
: Bool
\ Pure
with
Order[k]
Returns true if and only if t contains the key k.
def
minimumKey
[kv]
(
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ Pure
Extracts k => v where k is the leftmost (i.e. smallest) key in the tree.
def
parCount
[kv]
(
n :
Int32
f :
k -> (v -> Bool)
t :
RedBlackTree[k, v]
)
: Int32
\ Pure
Applies f over the tree t in parallel and returns the number of elements
that satisfy the predicate f.
The implementation spawns n threads each applying f sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
def
parExists
[kv]
(
n :
Int32
f :
k -> (v -> Bool)
t :
RedBlackTree[k, v]
)
: Bool
\ Pure
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.
def
parForAll
[kv]
(
n :
Int32
f :
k -> (v -> Bool)
t :
RedBlackTree[k, v]
)
: Bool
\ Pure
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.
def
parMaximumBy
[kv]
(
n :
Int32
cmp :
k -> (v -> (k -> (v -> Comparison)))
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ Pure
Applies cmp over the tree t in parallel and optionally returns the largest
element according to cmp.
The implementation spawns n threads each applying cmp sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
def
parMinimumBy
[kv]
(
n :
Int32
cmp :
k -> (v -> (k -> (v -> Comparison)))
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ Pure
Applies cmp over the tree t in parallel and optionally returns the lowest
element according to cmp.
The implementation spawns n threads each applying cmp sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
def
parSumWith
[kv]
(
n :
Int32
f :
k -> (v -> Int32)
t :
RedBlackTree[k, v]
)
: Int32
\ Pure
Returns the sum of all key-value pairs k => v in the tree t
according to the function f.
The implementation spawns n threads each applying f sequentially
from left to right on some subtree that is disjoint from the rest of
the threads.
def
query
[kef1vef2a]
(
p :
k -> Comparison \ ef1
f :
k -> (v -> a \ ef2)
t :
RedBlackTree[k, v]
)
: List[a]
\ ef1 + ef2
Extracts 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
queryWith
[kef1vef2]
(
p :
k -> Comparison \ ef1
f :
k -> (v -> Unit \ ef2)
t :
RedBlackTree[k, v]
)
: Unit
\ ef1 + ef2
Applies f to all key-value pairs from t where p(k) returns Comparison.EqualTo.
The function f must be impure.
def
reduceLeft
[kvef]
(
f :
k -> (v -> (k -> (v -> (k, v) \ ef)))
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ ef
Applies 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
[kvef]
(
f :
k -> (v -> (k -> (v -> (k, v) \ ef)))
t :
RedBlackTree[k, v]
)
: Option[(k, v)]
\ ef
Applies 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.
def
remove
[kv]
(
k :
k
t :
RedBlackTree[k, v]
)
: RedBlackTree[k, v]
\ Pure
with
Order[k]
Removes k => v from t if t contains the key k.
Otherwise, returns t.
def
size
[kv]
(
t :
RedBlackTree[k, v]
)
: Int32
\ Pure
Returns the number of nodes in t.
def
sumKeys
[v]
(
t :
RedBlackTree[Int32, v]
)
: Int32
\ Pure
Returns the sum of all keys in the tree t.
def
sumValues
[k]
(
t :
RedBlackTree[k, Int32]
)
: Int32
\ Pure
Returns the sum of all values in the tree t.
def
sumWith
[kvef]
(
f :
k -> (v -> Int32 \ ef)
t :
RedBlackTree[k, v]
)
: Int32
\ ef
Returns the sum of all key-value pairs k => v in the tree t
according to the function f.
def
toList
[kv]
(
t :
RedBlackTree[k, v]
)
: List[(k, v)]
\ Pure
Returns the tree t as a list. Elements are ordered from smallest (left) to largest (right).
def
toMutDeque
[rkv]
(
rc :
Region[r]
t :
RedBlackTree[k, v]
)
: MutDeque[(k, v), r]
\ r
Returns the tree t as a MutDeque. Elements are ordered from smallest (left) to largest (right).
def
updateWith
[kvef]
(
f :
k -> (v -> Option[v] \ ef)
k :
k
t :
RedBlackTree[k, v]
)
: RedBlackTree[k, v]
\ ef
with
Order[k]
Updates t with k => v1 if k => v is in t and f(k, v) = Some(v1).
Otherwise, returns t.