External-memory closed-interval queries on classic B-trees #
Closed-interval range queries (rangeR) over the PFunctor.FreeM node-access oracle of
Cslib.DataStructure.BTree.NodeAccess. rangeR takes only a descent bound fuel : ℕ, interval
endpoints lo hi : α, and an optional root handle root : Option H: empty leaves (none) return
[] with 0 page reads, and each entered node (some h) issues one readNode query before
rangeScan traverses its separator triples in memory, pruning any child excluded by its adjacent
separators.
When Denotes s root tr and tr.height ≤ fuel:
eval_rangeRproveseval s (rangeR fuel lo hi root) = BTree.range lo hi tr.countQueries_rangeR_eqprovescountQueries s (rangeR fuel lo hi root) = rangeVisits lo hi tr, the structural page-read count ontr.countQueries_rangeR_of_occupied,countQueries_rangeR, andcountQueries_rangeR_le_logbound the page reads by2 * tr.height + (BTree.range lo hi tr).length(and2 * (Nat.log t ((tr.size + 1) / 2) + 1) + (BTree.range lo hi tr).lengthonIsWF t tr): a subtree wholly inside[lo, hi]reads at most one page per returned entry because every occupied node holds at least one key when2 ≤ t, while at each depth at most one node straddlesloand at most one straddleshi.
Main definitions #
NodeAccess.rangeScan,NodeAccess.rangeR: closed-interval query overnodeQuery.NodeAccess.rangeVisits: pure page-read recurrence onBTree α βcharacterizingrangeR's structural query count.
Main results #
NodeAccess.eval_rangeR:evalequalsBTree.rangeunderDenotes s root trandtr.height ≤ fuel.NodeAccess.countQueries_rangeR_eq:countQueriesequalsrangeVisits lo hi trunderDenotes s root trandtr.height ≤ fuel.NodeAccess.countQueries_rangeR_of_occupied,NodeAccess.countQueries_rangeR,NodeAccess.countQueries_rangeR_le_log: output-sensitive2 * height + kand logarithmic page-read bounds.
References #
Adapted from cslib-community/EpsilonEridani at commit 1966ab476
(EpsilonEridani/Algorithms/Lean/BTree/Cost/Range.lean),
recast from monadic node-visit annotations to structural PFunctor.FreeM page-read queries.
Within-page scan for rangeR: traverses an already-read page's entries without issuing extra
page reads for the current node, recursing into children permitted by [lo, hi].
External-memory closed-interval query [lo, hi] over nodeQuery.
Structural page-read count of a pruned closed-interval traversal on BTree α β.
Exact agreement with BTree.range and rangeVisits #
rangeR issues rangeVisits lo hi tr page reads when root denotes tr and
tr.height ≤ fuel.
Output-sensitive 2 * height + k page-read bounds #
Pure page-visit bound rangeVisits lo hi tr ≤ 2 * tr.height + (BTree.range lo hi tr).length
on any sorted tree whose children satisfy Occupied t for 2 ≤ t.
rangeR issues at most 2 * tr.height + (BTree.range lo hi tr).length page reads on any
sorted tree with Occupied t children (2 ≤ t) when Denotes s root tr and tr.height ≤ fuel.
rangeR issues at most 2 * tr.height + (BTree.range lo hi tr).length page reads on a
well-formed B-tree when Denotes s root tr and tr.height ≤ fuel.
Logarithmic O(log_t n + k) page-read bound for rangeR on a well-formed B-tree.