pub struct SortedVecCursor<'a, K>where
K: DenseId,{ /* private fields */ }Expand description
Cursor into a bucket slice: the verified galloping cursor from
containers-verus, re-exported so this module’s public surface is unchanged.
The seek is proven, not just tested: it lands on the first key >= target
and skips no present key, for every slice and every target, with every slice
index in bounds and no arithmetic overflow. The proof is stated against the
same seek_target_idx spec function the verified B+tree cursor uses, which
is what makes the two substitutable at the SortedCursor boundary.
See containers-verus/doc/design/12-sorted-vec-cursor.md. The algorithm and
the #[inline] attributes match what this module previously defined inline;
the erased build compiles the same doubling ladder and bounded bisection.
Cursor over a sorted, duplicate-free slice of ids.
pos is both the executable position and the model index — unlike
BPlusCursor, whose (node, pos) pair needs a ghost gidx to name its
place in the model, an array-backed cursor’s position is its model index.
That is the whole reason this cursor’s proofs are short: there is no
arena-to-model refinement to carry, only the seek arithmetic.
pos == data.len() marks “exhausted”. Production parity:
egraph/src/index.rs’s SortedVecCursor { data, pos }, field for field.
Implementations§
Source§impl<'a, K> SortedVecCursor<'a, K>where
K: DenseId,
impl<'a, K> SortedVecCursor<'a, K>where
K: DenseId,
Sourcepub fn new(data: &'a [K]) -> SortedVecCursor<'a, K>
pub fn new(data: &'a [K]) -> SortedVecCursor<'a, K>
Position at the start of data. Requires-free: any slice is accepted,
and the cursor’s method contracts state their characterizations under
the hypothesis that the data’s model is strictly sorted (cursor_wf).
A caller that proves sortedness gets the full contracts; every caller
gets the in-bounds guarantees.
Sourcepub fn pos(&self) -> usize
pub fn pos(&self) -> usize
The cursor’s position, as a usize — the executable read of
Self::idx, which is a spec function and so invisible to a plain build.
Exists so a consumer (and the erased-build test harness) can observe the
position without reaching into the private field. Nothing in the proofs
needs it; the ensures is what makes it usable as an oracle.
Sourcepub fn key(&self) -> K
pub fn key(&self) -> K
The key at the cursor. Requires-free: exhaustion is refused at runtime, and the ensures needs no sortedness — it only ties the returned key to the model at the current position.
Sourcepub fn seek(&mut self, target: K)
pub fn seek(&mut self, target: K)
Advance to the first key >= target, or exhaust. Forward-only: a cursor
already at or past the target does not move.
Galloping doubles an offset from the cursor until it lands on or past the
target, then bisects the window
that offset just proved brackets the answer. O(log d) in the distance
advanced rather than O(log rem) in the remainder.
The postcondition is the whole soundness story in one line, and every
theorem below is a corollary of it: the new position is
seek_target_idx(model, target) — the count of model keys strictly below
the target, the same spec function BPlusCursor::seek lands on — except
where the cursor was already beyond it, in which case it stays.
#[inline] because this is the join layer’s hot path – called once per
leapfrog step through a generic cursor, where inlining also permits
devirtualization. Its machine effect is covered by the Criterion cursor
and saturation benchmarks.
The bisection below is written as an explicit loop rather than
data[lo+1..hi].partition_point(..) (which is what egraph called before
it adopted this cursor) because there is no way to state a loop invariant
through std’s partition_point. The explicit loop also gives the compiler
the code shape used by the maintained implementation; changing it requires
a Criterion comparison as well as the contract tests.
Requires-free: the sortedness hypothesis lives in the ensures as an
implication. On any input the gallop and the bisection stay in bounds
and terminate; the position never decreases and never leaves
[0, len] once inside it. Under cursor_wf the full forward-only
split-point characterization holds.
Trait Implementations§
Source§impl<'a, K> SortedCursor for SortedVecCursor<'a, K>
impl<'a, K> SortedCursor for SortedVecCursor<'a, K>
Source§fn key(&self) -> Option<K>
fn key(&self) -> Option<K>
The verified key refuses at runtime on an exhausted cursor rather than
returning Option, because production’s panics there (data[pos] past
the end). The is_valid guard here is what keeps that refusal
unreachable, and it is the only thing these three bodies add over the
BPlusCursor ones.