Documentation

CslibFrontier.DataStructure.BTree.NodeAccess.Query

External-memory point queries on classic B-trees #

Point queries (minR, maxR, lookupR, containsR, predR, succR, rankR) over the PFunctor.FreeM node-access oracle of Cslib.DataStructure.BTree.NodeAccess. Each program takes only a descent bound fuel : ℕ and an optional root handle root : Option H: empty leaves (none) return immediately with 0 page reads, and each dereferenced node handle (some h) issues one readNode (or readRankedNode for rankR) query before scanning the returned page in memory and descending into at most one child.

Consequently:

  1. Under every store s (even cyclic or malformed handle graphs), each query issues at most fuel page reads.
  2. Whenever Denotes s root tr (or DenotesRanked s root tr for rankR) and tr.height ≤ fuel, eval equals the pure BTree query (min?, max?, lookup, contains, pred?, succ?, rank) and countQueries is at most tr.height (independent of excess fuel), hence at most Nat.log t ((tr.size + 1) / 2) + 1 on any well-formed IsWF t tr.

Main definitions #

Main results #

References #

def Cslib.DataStructure.BTree.NodeAccess.minR {α β H : Type} :
ℕ → Option H → NodeM α β H (Option (α × β))

External-memory minimum query: follow first-child handles, reading at most one page per level.

def Cslib.DataStructure.BTree.NodeAccess.maxScan {α β H : Type} (rec : Option H → NodeM α β H (Option (α × β))) :
Option H → List (PageEntry α β H) → NodeM α β H (Option (α × β))

Within-page scan for maxR: walks to the last entry of an already-read page without issuing extra reads, then recurses into the rightmost child.

def Cslib.DataStructure.BTree.NodeAccess.maxR {α β H : Type} :
ℕ → Option H → NodeM α β H (Option (α × β))

External-memory maximum query: read each page along the rightmost spine once.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_minR_le_fuel {α β H : Type} (s : Store α β H) (fuel : ℕ) (root : Option H) :
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_maxR_le_fuel {α β H : Type} (s : Store α β H) (fuel : ℕ) (root : Option H) :
theorem Cslib.DataStructure.BTree.NodeAccess.eval_minR {α β H : Type} {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) :
PFunctor.FreeM.eval s (minR fuel root) = tr.min?

minR evaluates to BTree.min? whenever root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_minR_le {α β H : Type} {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) :

minR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.eval_maxR {α β H : Type} {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) :
PFunctor.FreeM.eval s (maxR fuel root) = tr.max?

maxR evaluates to BTree.max? whenever root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_maxR_le {α β H : Type} {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) :

maxR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

def Cslib.DataStructure.BTree.NodeAccess.lookupScan {α β H : Type} [LinearOrder α] (rec : Option H → NodeM α β H (Option β)) (k : α) :
Option H → List (PageEntry α β H) → NodeM α β H (Option β)

Within-page scan for lookupR: scans keys in memory and either returns on equality or recurses into the single selected child handle.

def Cslib.DataStructure.BTree.NodeAccess.lookupR {α β H : Type} [LinearOrder α] :
ℕ → α → Option H → NodeM α β H (Option β)

External-memory lookup query: reads at most one page per level along the search path.

def Cslib.DataStructure.BTree.NodeAccess.containsR {α β H : Type} [LinearOrder α] (fuel : ℕ) (k : α) (root : Option H) :
NodeM α β H Bool

External-memory membership test, derived from lookupR at the same page-read cost.

def Cslib.DataStructure.BTree.NodeAccess.predScan {α β H : Type} [LinearOrder α] (rec : Option H → NodeM α β H (Option (α × β))) (k : α) :
Option H → List (PageEntry α β H) → NodeM α β H (Option (α × β))

Within-page scan for predR: scans keys in memory, retaining smaller separators as fallbacks, and recurses into at most one child handle.

def Cslib.DataStructure.BTree.NodeAccess.predR {α β H : Type} [LinearOrder α] :
ℕ → α → Option H → NodeM α β H (Option (α × β))

External-memory strict predecessor query.

def Cslib.DataStructure.BTree.NodeAccess.succScan {α β H : Type} [LinearOrder α] (rec : Option H → NodeM α β H (Option (α × β))) (k : α) :
Option H → List (PageEntry α β H) → NodeM α β H (Option (α × β))

Within-page scan for succR: skips keys ≤ k in memory and recurses into the child before the first larger separator (or the rightmost child).

def Cslib.DataStructure.BTree.NodeAccess.succR {α β H : Type} [LinearOrder α] :
ℕ → α → Option H → NodeM α β H (Option (α × β))

External-memory strict successor query.

def Cslib.DataStructure.BTree.NodeAccess.rankScan {α β H : Type} [LinearOrder α] (rec : Option H → RankedNodeM α β H ℕ) (k : α) :
RankedChild H → List (RankedPageEntry α β H) → RankedNodeM α β H ℕ

Within-page scan for rankR in an order-statistic page: accumulates stored child sizes of skipped children in memory without reading those children's pages.

External-memory strict rank query over rankedNodeQuery.

Universal ≤ fuel bounds #

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_lookupR_le_fuel {α β H : Type} [LinearOrder α] (s : Store α β H) (fuel : ℕ) (k : α) (root : Option H) :
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_containsR_le_fuel {α β H : Type} [LinearOrder α] (s : Store α β H) (fuel : ℕ) (k : α) (root : Option H) :
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_predR_le_fuel {α β H : Type} [LinearOrder α] (s : Store α β H) (fuel : ℕ) (k : α) (root : Option H) :
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_succR_le_fuel {α β H : Type} [LinearOrder α] (s : Store α β H) (fuel : ℕ) (k : α) (root : Option H) :
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_rankR_le_fuel {α β H : Type} [LinearOrder α] (s : RankedStore α β H) (fuel : ℕ) (k : α) (root : Option H) :

Exact pure-model agreement and ≤ tr.height page-read bounds #

theorem Cslib.DataStructure.BTree.NodeAccess.eval_lookupR {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.eval s (lookupR fuel k root) = lookup k tr

lookupR evaluates to BTree.lookup whenever root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_lookupR_le {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :

lookupR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.eval_containsR {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :

containsR evaluates to BTree.contains when root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_containsR_le {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :

containsR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.eval_predR {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.eval s (predR fuel k root) = pred? k tr

predR evaluates to BTree.pred? whenever root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_predR_le {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :

predR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.eval_succR {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.eval s (succR fuel k root) = succ? k tr

succR evaluates to BTree.succ? whenever root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_succR_le {α β H : Type} [LinearOrder α] {s : Store α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :

succR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.eval_rankR {α β H : Type} [LinearOrder α] {s : RankedStore α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : DenotesRanked s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.eval s (rankR fuel k root) = rank k tr

rankR evaluates to BTree.rank whenever root denotes tr in RankedStore s and tr.height ≤ fuel.

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_rankR_le {α β H : Type} [LinearOrder α] {s : RankedStore α β H} {fuel : ℕ} {root : Option H} {tr : BTree α β} (hd : DenotesRanked s root tr) (hf : tr.height ≤ fuel) (k : α) :

rankR reads at most tr.height pages when root denotes tr and tr.height ≤ fuel.

Logarithmic O(log_t n) page-read corollaries on well-formed B-trees #

theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_minR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : Store α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : Denotes s root tr) (hf : tr.height ≤ fuel) :
PFunctor.FreeM.countQueries s (minR fuel root) ≤ Nat.log t ((tr.size + 1) / 2) + 1
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_maxR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : Store α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : Denotes s root tr) (hf : tr.height ≤ fuel) :
PFunctor.FreeM.countQueries s (maxR fuel root) ≤ Nat.log t ((tr.size + 1) / 2) + 1
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_lookupR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : Store α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.countQueries s (lookupR fuel k root) ≤ Nat.log t ((tr.size + 1) / 2) + 1
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_containsR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : Store α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.countQueries s (containsR fuel k root) ≤ Nat.log t ((tr.size + 1) / 2) + 1
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_predR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : Store α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.countQueries s (predR fuel k root) ≤ Nat.log t ((tr.size + 1) / 2) + 1
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_succR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : Store α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : Denotes s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.countQueries s (succR fuel k root) ≤ Nat.log t ((tr.size + 1) / 2) + 1
theorem Cslib.DataStructure.BTree.NodeAccess.countQueries_rankR_le_log {α β H : Type} [LinearOrder α] {t fuel : ℕ} {s : RankedStore α β H} {root : Option H} {tr : BTree α β} (hwf : IsWF t tr) (hd : DenotesRanked s root tr) (hf : tr.height ≤ fuel) (k : α) :
PFunctor.FreeM.countQueries s (rankR fuel k root) ≤ Nat.log t ((tr.size + 1) / 2) + 1