Removing the least and greatest entries of classic B-trees #
eraseMinM and eraseMaxM remove and return the least and greatest entries of a B-tree: they
find the extreme entry with minM or maxM and erase its key with eraseM, over an arbitrary
monad with a comparator and a node-visit action. The pure operations are the Id
instantiations with leI and visit := pure (). Costs are not stated here.
Main definitions #
eraseMinM,eraseMin?: remove and return the least entry.eraseMaxM,eraseMax?: remove and return the greatest entry.
Main results #
Cslib.IsMonadHom.map_eraseMinM,Cslib.IsMonadHom.map_eraseMaxM: a monad morphism commutes with the operations.eraseMin?_eq,eraseMax?_eq: the model equations, on any tree: the first or last entry oftoListtogether with the erasure of its key.toList_of_eraseMin?_eq_some,toList_of_eraseMax?_eq_some: on a well-formed tree, the entries split into the removed entry and those of a well-formed rest.
Ported from cslib-community/EpsilonEridani at commit 1966ab476:
EpsilonEridani/Algorithms/Lean/BTree/Erase/MinMax.lean.
A monad morphism commutes with the removal of the least entry.
A monad morphism commutes with the removal of the greatest entry.
Remove and return the least entry, pure.
Remove and return the greatest entry, pure.
The empty tree has no least entry to remove.
The empty tree has no greatest entry to remove.
eraseMin? returns p and tr' exactly when p is the first entry and tr' the tree with
its key erased.
eraseMax? returns p and tr' exactly when p is the last entry and tr' the tree with
its key erased.
On a tree with sorted entries, eraseMin? splits the entries into the first and the rest.
On a tree with sorted entries, eraseMax? splits the entries into the rest and the last.
On a well-formed tree, eraseMin? splits the entries into the first and the rest, and the
rest is well-formed.
On a well-formed tree, eraseMax? splits the entries into the rest and the last, and the
rest is well-formed.