Additional lemmas for Red-black trees #
O(n)
. depth t
is the maximum number of nodes on any path to a leaf.
It is an upper bound on most tree operations.
Equations
- Std.RBNode.depth Std.RBNode.nil = 0
- Std.RBNode.depth (Std.RBNode.node c a v b) = max (Std.RBNode.depth a) (Std.RBNode.depth b) + 1
Instances For
depthLB c n
is the best upper bound on the depth of any balanced red-black tree
with root colored c
and black-height n
.
Equations
- Std.RBNode.depthLB x✝ x = match x✝, x with | Std.RBColor.red, n => n + 1 | Std.RBColor.black, n => n
Instances For
depthUB c n
is the best upper bound on the depth of any balanced red-black tree
with root colored c
and black-height n
.
Equations
- Std.RBNode.depthUB x✝ x = match x✝, x with | Std.RBColor.red, n => 2 * n + 1 | Std.RBColor.black, n => 2 * n
Instances For
A well formed tree has t.depth ∈ O(log t.size)
, that is, it is well balanced.
This justifies the O(log n)
bounds on most searching operations of RBSet
.
Equations
- Std.RBNode.instDecidableOrdered cmp t = decidable_of_iff (Std.RBNode.isOrdered cmp t none = true) ⋯
A cut is like a homomorphism of orderings: it is a monotonic predicate with respect to cmp
,
but it can make things that are distinguished by cmp
equal.
This is sufficient for find?
to locate an element on which cut
returns .eq
,
but there may be other elements, not returned by find?
, on which cut
also returns .eq
.
- le_lt_trans : ∀ {x y : α} [inst : Std.TransCmp cmp], cmp x y ≠ Ordering.gt → cut x = Ordering.lt → cut y = Ordering.lt
The set
{x | cut x = .lt}
is downward-closed. - le_gt_trans : ∀ {x y : α} [inst : Std.TransCmp cmp], cmp x y ≠ Ordering.gt → cut y = Ordering.gt → cut x = Ordering.gt
The set
{x | cut x = .gt}
is upward-closed.
Instances
IsStrictCut
upgrades the IsCut
property to ensure that at most one element of the tree
can match the cut, and hence find?
will return the unique such element if one exists.
- le_lt_trans : ∀ {x y : α} [inst : Std.TransCmp cmp], cmp x y ≠ Ordering.gt → cut x = Ordering.lt → cut y = Ordering.lt
- le_gt_trans : ∀ {x y : α} [inst : Std.TransCmp cmp], cmp x y ≠ Ordering.gt → cut y = Ordering.gt → cut x = Ordering.gt
- exact : ∀ {x y : α} [inst : Std.TransCmp cmp], cut x = Ordering.eq → cmp x y = cut y
If
cut = x
, thencut
andx
have compare the same with respect to other elements.
Instances
A "representable cut" is one generated by cmp a
for some a
. This is always a valid cut.
Equations
- ⋯ = ⋯
The value x
returned by lowerBound?
is less or equal to the cut
.
The value x
returned by lowerBound?
is less or equal to the cut
.
A statement of the least-ness of the result of lowerBound?
. If x
is the return value of
lowerBound?
and it is strictly less than the cut, then any other y > x
in the tree is in fact
strictly greater than the cut (so there is no exact match, and nothing closer to the cut).
A stronger version of lowerBound?_least
that holds when the cut is strict.
The list of elements to the left of the hole. (This function is intended for specification purposes only.)
Equations
- Std.RBNode.Path.listL Std.RBNode.Path.root = []
- Std.RBNode.Path.listL (Std.RBNode.Path.left c parent v r) = Std.RBNode.Path.listL parent
- Std.RBNode.Path.listL (Std.RBNode.Path.right c l v parent) = Std.RBNode.Path.listL parent ++ (Std.RBNode.toList l ++ [v])
Instances For
The list of elements to the right of the hole. (This function is intended for specification purposes only.)
Equations
- Std.RBNode.Path.listR Std.RBNode.Path.root = []
- Std.RBNode.Path.listR (Std.RBNode.Path.left c parent v r) = v :: Std.RBNode.toList r ++ Std.RBNode.Path.listR parent
- Std.RBNode.Path.listR (Std.RBNode.Path.right c l v parent) = Std.RBNode.Path.listR parent
Instances For
Wraps a list of elements with the left and right elements of the path.
Equations
Instances For
Equations
- Std.RBSet.instDecidableMemRBSetInstMembershipRBSet = decidable_of_iff (Std.RBSet.contains t x = true) ⋯