Range queries in B+-trees #
rangeM lo hi returns the entries whose keys lie in the closed interval [lo, hi], in key
order. At an interior node it walks along the separators. The child before a separator s holds
keys below s, so it is entered only when s is not at most lo; the children after s hold
keys that are at least s, so the walk goes on only while s is at most hi. That is two
comparisons per separator reached. In a leaf it runs the scan Cslib.SortedAssoc.rangeM of the
entry list. visit fires once at each node entered, the leaves included. Costs are not stated
here.
The walk enters children one after another; it does not follow a chain of leaves. What a chained
implementation would return is described by range_eq_flatten_run: the output is the
restriction of a contiguous run of leaves, every leaf of the run contributes, and every leaf of
the run other than its first and last is returned whole.
Main definitions #
Main results #
map_rangeM: a monad morphism commutes with the query.range_eq: on a well-formed tree,rangeisSortedAssoc.rangeontoList.Occupied.ne_nil_of_mem_leaves: an occupied tree has no empty leaf when2 ≤ t.range_eq_flatten_run: on a well-formed tree, the output is the restriction of a contiguous run of leaves whose interior leaves are returned whole.
Entries with key in the closed interval [lo, hi]. Walk along the separators of a node:
enter the child before a separator unless the separator is at most lo, and go on past the
separator only when it is at most hi; in a leaf, scan the entries. visit fires once at each
node entered, when the walk along its separators ends.
A monad morphism commutes with the range query.
Pure range restriction: the Id instantiation of rangeM with visit := pure ().
Range restriction of a leaf is the scan of its entries.
Range restriction at a node's first separator: the child before it contributes unless the
separator is at most lo, and what follows it contributes when the separator is at most hi.
Model equation of range restriction on well-formed trees.
On a well-formed tree, the output of a range query is the restriction of a contiguous run of
leaves in which every leaf contributes and every leaf other than the first and last is returned
whole. Without the last two conjuncts the run could be all of leaves.