Skip to main content

PostingCursor

Trait PostingCursor 

Source
pub trait PostingCursor {
    // Required methods
    fn peek(&self) -> Option<Posting>;
    fn advance(&mut self);
    fn seek(&mut self, target: RecordId) -> Option<Posting>;
    fn remaining(&self) -> usize;
    fn last_id(&self) -> Option<RecordId>;
    fn exhaust(&mut self);

    // Provided methods
    fn upper_bound(&self) -> Weight { ... }
    fn lower_bound(&self) -> Weight { ... }
    fn drain_through(
        &mut self,
        hi: RecordId,
        visit: impl FnMut(RecordId, Weight),
    ) { ... }
    fn is_exhausted(&self) -> bool { ... }
}
Expand description

A forward-only reader over one posting list, sorted by record id.

A cursor is always positioned either on an element (the current one, returned by peek) or past the end. It only ever moves forward: seek with a target at or below the current id is a no-op that returns the current element, and moving backwards is never required by the search loop.

Implementations back the cursor with any storage — a Vec in RAM, an mmap’d slice, a decoded block — as long as they honour the ceiling invariant: upper_bound is at least the weight of every element from the current position to the end of the list.

Required Methods§

Source

fn peek(&self) -> Option<Posting>

The current element, or None once the cursor is past the end.

Source

fn advance(&mut self)

Move to the next element (no-op past the end).

Source

fn seek(&mut self, target: RecordId) -> Option<Posting>

Move forward to the first element whose id is >= target and return it. Returns None when no such element exists; the cursor is then past the end. Never moves backwards.

Source

fn remaining(&self) -> usize

Number of elements not yet consumed, the current one included.

Source

fn last_id(&self) -> Option<RecordId>

Id of the last element of the whole list (regardless of position); None for an empty list.

Source

fn exhaust(&mut self)

Move past the end.

Provided Methods§

Source

fn upper_bound(&self) -> Weight

An upper bound on the weights of the elements not yet consumed, the current one included. f32::NEG_INFINITY once past the end.

Source

fn lower_bound(&self) -> Weight

A lower bound on the weights of the elements not yet consumed. The default is unbounded, which is always correct; storages that track a suffix minimum can tighten it so negative query weights prune too.

Source

fn drain_through(&mut self, hi: RecordId, visit: impl FnMut(RecordId, Weight))

Consume every element with id <= hi, handing each (id, weight) to visit in id order. Leaves the cursor on the first element above hi (or past the end).

Source

fn is_exhausted(&self) -> bool

True once the cursor is past the end.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§