Documentation

CslibFrontier.DataStructure.BPlusTree.Erase.MinMax

Removing the least and the greatest entry of a B+-tree #

eraseMinM and eraseMaxM find the least or the greatest entry of a B+-tree of Cslib.DataStructure.BPlusTree with minM or maxM and then erase its key with eraseM, as the classic Cslib.DataStructure.BTree.eraseMinM does. Each is defined once over an arbitrary monad, with a comparator and a node-visit action; eraseMin? and eraseMax? are the Id instantiations. The tree is walked twice, once to find the entry and once to erase it. Costs are not stated here.

Main definitions #

Main results #

References #

The statements here are not taken from a source.

def Cslib.DataStructure.BPlusTree.eraseMinM {α β : Type} {m : Type → Type w} [Monad m] (t : ℕ) (le : α → α → m Bool) (visit : m Unit) (tr : BPlusTree α β) :
m (Option ((α × β) × BPlusTree α β))

Remove and return the least entry: find it with minM, then erase its key.

def Cslib.DataStructure.BPlusTree.eraseMaxM {α β : Type} {m : Type → Type w} [Monad m] (t : ℕ) (le : α → α → m Bool) (visit : m Unit) (tr : BPlusTree α β) :
m (Option ((α × β) × BPlusTree α β))

Remove and return the greatest entry: find it with maxM, then erase its key.

theorem Cslib.DataStructure.BPlusTree.eraseMinM_def {α β : Type} {m : Type → Type w} [Monad m] (t : ℕ) (le : α → α → m Bool) (visit : m Unit) (tr : BPlusTree α β) :
eraseMinM t le visit tr = do let __do_lift ← minM visit tr match __do_lift with | none => pure none | some p => do let __do_lift ← eraseM t le visit p.1 tr pure (some (p, __do_lift))

Removing the least entry finds it with minM, then erases its key.

theorem Cslib.DataStructure.BPlusTree.eraseMaxM_def {α β : Type} {m : Type → Type w} [Monad m] (t : ℕ) (le : α → α → m Bool) (visit : m Unit) (tr : BPlusTree α β) :
eraseMaxM t le visit tr = do let __do_lift ← maxM visit tr match __do_lift with | none => pure none | some p => do let __do_lift ← eraseM t le visit p.1 tr pure (some (p, __do_lift))

Removing the greatest entry finds it with maxM, then erases its key.

theorem Cslib.DataStructure.BPlusTree.map_eraseMinM {α β : 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) (t : ℕ) (le : α → α → m Bool) (visit : m Unit) (tr : BPlusTree α β) :
f (eraseMinM t le visit tr) = eraseMinM t (fun (a b : α) => f (le a b)) (f visit) tr

A monad morphism commutes with the removal of the least entry.

theorem Cslib.DataStructure.BPlusTree.map_eraseMaxM {α β : 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) (t : ℕ) (le : α → α → m Bool) (visit : m Unit) (tr : BPlusTree α β) :
f (eraseMaxM t le visit tr) = eraseMaxM t (fun (a b : α) => f (le a b)) (f visit) tr

A monad morphism commutes with the removal of the greatest entry.

def Cslib.DataStructure.BPlusTree.eraseMin? {α β : Type} [LinearOrder α] (t : ℕ) (tr : BPlusTree α β) :
Option ((α × β) × BPlusTree α β)

Remove and return the least entry, pure.

def Cslib.DataStructure.BPlusTree.eraseMax? {α β : Type} [LinearOrder α] (t : ℕ) (tr : BPlusTree α β) :
Option ((α × β) × BPlusTree α β)

Remove and return the greatest entry, pure.

eraseMin? is the Id instantiation of eraseMinM.

eraseMax? is the Id instantiation of eraseMaxM.

theorem Cslib.DataStructure.BPlusTree.eraseMin?_eq_map_min? {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} :
eraseMin? t tr = Option.map (fun (p : α × β) => (p, erase t p.1 tr)) tr.min?

eraseMin? is the least entry together with the erasure of its key.

theorem Cslib.DataStructure.BPlusTree.eraseMax?_eq_map_max? {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} :
eraseMax? t tr = Option.map (fun (p : α × β) => (p, erase t p.1 tr)) tr.max?

eraseMax? is the greatest entry together with the erasure of its key.

theorem Cslib.DataStructure.BPlusTree.eraseMin?_eq {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) :
eraseMin? t tr = Option.map (fun (p : α × β) => (p, erase t p.1 tr)) tr.toList.head?

Model equation of eraseMin? on well-formed trees: the first entry and the tree with its key erased.

theorem Cslib.DataStructure.BPlusTree.eraseMax?_eq {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) :
eraseMax? t tr = Option.map (fun (p : α × β) => (p, erase t p.1 tr)) tr.toList.getLast?

Model equation of eraseMax? on well-formed trees: the last entry and the tree with its key erased.

theorem Cslib.DataStructure.BPlusTree.eraseMin?_eq_some_iff {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) {p : α × β} {tr' : BPlusTree α β} :
eraseMin? t tr = some (p, tr') ↔ tr.toList.head? = some p ∧ tr' = erase t p.1 tr

On a well-formed tree, eraseMin? returns p and tr' exactly when p is the first entry and tr' the tree with its key erased.

theorem Cslib.DataStructure.BPlusTree.eraseMax?_eq_some_iff {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) {p : α × β} {tr' : BPlusTree α β} :
eraseMax? t tr = some (p, tr') ↔ tr.toList.getLast? = some p ∧ tr' = erase t p.1 tr

On a well-formed tree, eraseMax? returns p and tr' exactly when p is the last entry and tr' the tree with its key erased.

theorem Cslib.DataStructure.BPlusTree.toList_of_eraseMin?_eq_some {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) {p : α × β} {tr' : BPlusTree α β} (he : eraseMin? t tr = some (p, tr')) :

On a well-formed tree, the tree that eraseMin? returns has the entries after the first.

theorem Cslib.DataStructure.BPlusTree.toList_of_eraseMax?_eq_some {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) {p : α × β} {tr' : BPlusTree α β} (he : eraseMax? t tr = some (p, tr')) :

On a well-formed tree, the tree that eraseMax? returns has the entries before the last.

theorem Cslib.DataStructure.BPlusTree.IsWF.of_eraseMin?_eq_some {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) {p : α × β} {tr' : BPlusTree α β} (he : eraseMin? t tr = some (p, tr')) :
IsWF t tr'

On a well-formed tree, the tree that eraseMin? returns is well-formed.

theorem Cslib.DataStructure.BPlusTree.IsWF.of_eraseMax?_eq_some {α β : Type} [LinearOrder α] {t : ℕ} {tr : BPlusTree α β} (h : IsWF t tr) {p : α × β} {tr' : BPlusTree α β} (he : eraseMax? t tr = some (p, tr')) :
IsWF t tr'

On a well-formed tree, the tree that eraseMax? returns is well-formed.