Documentation

CslibFrontier.DataStructure.BPlusTree.MinMax

Least and greatest entries of B+-trees #

The least entry of a B+-tree is the first entry of its leftmost leaf, and the greatest is the last entry of its rightmost leaf. minM and maxM walk to that leaf through first, respectively last, children. They compare no keys, so they take only the node-visit action visit, which fires once at each node on the path, the leaf included. The pure operations are the Id instantiations with visit := pure ().

The model equations need the leaf that the walk reaches to be non-empty unless it is the root. They are stated for occupied subtrees at 2 ≤ t, which is what the sibling fallback of pred? and succ? uses, and for well-formed trees.

Main definitions #

Main results #

def Cslib.DataStructure.BPlusTree.minM {α β : Type} {m : Type → Type w} [Monad m] (visit : m Unit) :
BPlusTree α β → m (Option (α × β))

Least entry: descend through first children to the leftmost leaf and return its first entry. visit fires once at each node on the path.

@[irreducible]
def Cslib.DataStructure.BPlusTree.maxM {α β : Type} {m : Type → Type w} [Monad m] (visit : m Unit) :
BPlusTree α β → m (Option (α × β))

Greatest entry: walk along the separators of each node, which is free, descend through last children to the rightmost leaf and return its last entry. visit fires once at each node on the path.

theorem Cslib.DataStructure.BPlusTree.map_minM {α β : Type} {m : Type → Type u_1} {n : Type → Type u_2} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (visit : m Unit) (tr : BPlusTree α β) :
f (minM visit tr) = minM (f visit) tr

A monad morphism commutes with the walk to the least entry.

theorem Cslib.DataStructure.BPlusTree.map_maxM {α β : Type} {m : Type → Type u_1} {n : Type → Type u_2} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (visit : m Unit) (tr : BPlusTree α β) :
f (maxM visit tr) = maxM (f visit) tr

A monad morphism commutes with the walk to the greatest entry.

def Cslib.DataStructure.BPlusTree.min? {α β : Type} (tr : BPlusTree α β) :
Option (α × β)

Pure least entry: the Id instantiation of minM with visit := pure ().

def Cslib.DataStructure.BPlusTree.max? {α β : Type} (tr : BPlusTree α β) :
Option (α × β)

Pure greatest entry: the Id instantiation of maxM with visit := pure ().

theorem Cslib.DataStructure.BPlusTree.min?_def {α β : Type} {tr : BPlusTree α β} :
tr.min? = (minM (pure ()) tr).run

min? is the Id instantiation of minM.

theorem Cslib.DataStructure.BPlusTree.max?_def {α β : Type} {tr : BPlusTree α β} :
tr.max? = (maxM (pure ()) tr).run

max? is the Id instantiation of maxM.

@[simp]
theorem Cslib.DataStructure.BPlusTree.min?_leaf {α β : Type} (entries : List (α × β)) :
(leaf entries).min? = entries.head?

The least entry of a leaf is its first entry.

@[simp]
theorem Cslib.DataStructure.BPlusTree.min?_node {α β : Type} (first : BPlusTree α β) (rest : List (Branch α β)) :
(first.node rest).min? = first.min?

The least entry of a node is that of its first child.

@[simp]
theorem Cslib.DataStructure.BPlusTree.max?_leaf {α β : Type} (entries : List (α × β)) :
(leaf entries).max? = entries.getLast?

The greatest entry of a leaf is its last entry.

@[simp]
theorem Cslib.DataStructure.BPlusTree.max?_node_nil {α β : Type} (first : BPlusTree α β) :
(first.node []).max? = first.max?

The greatest entry of a node without separators is that of its only child.

@[simp]
theorem Cslib.DataStructure.BPlusTree.max?_node_cons {α β : Type} (s : α) (first c : BPlusTree α β) (rest : List (Branch α β)) :
(first.node ((s, c) :: rest)).max? = (c.node rest).max?

The greatest entry of a node is that of the node without its first child and separator.

theorem Cslib.DataStructure.BPlusTree.Occupied.toList_ne_nil {α β : Type} {t : ℕ} {tr : BPlusTree α β} (ht : 2 ≤ t) (ho : Occupied t tr) :

An occupied tree has a non-empty entry list when 2 ≤ t.

theorem Cslib.DataStructure.BPlusTree.Occupied.min?_eq {α β : Type} {t : ℕ} {tr : BPlusTree α β} (ht : 2 ≤ t) (ho : Occupied t tr) :

The least entry of an occupied subtree at 2 ≤ t is the first entry of toList.

theorem Cslib.DataStructure.BPlusTree.Occupied.max?_eq {α β : Type} {t : ℕ} {tr : BPlusTree α β} (ht : 2 ≤ t) (ho : Occupied t tr) :

The greatest entry of an occupied subtree at 2 ≤ t is the last entry of toList.

theorem Cslib.DataStructure.BPlusTree.min?_eq {α β : Type} {t : ℕ} {tr : BPlusTree α β} [LinearOrder α] (h : IsWF t tr) :

Model equation of the least entry on well-formed trees.

theorem Cslib.DataStructure.BPlusTree.max?_eq {α β : Type} {t : ℕ} {tr : BPlusTree α β} [LinearOrder α] (h : IsWF t tr) :

Model equation of the greatest entry on well-formed trees.