KeyedCursor

Trait KeyedCursor 

Source
pub trait KeyedCursor<Key: Ord>: Cursor {
    // Required method
    fn get_key(&self) -> Option<Key>;

    // Provided methods
    fn jump_near_key(&mut self, _key: &Key, _direction: Direction) { ... }
    fn jump_to_key(&mut self, key: &Key, direction: Direction) -> Result<bool> { ... }
    fn get_near(
        &mut self,
        key: &Key,
        preferred_direction: Direction,
    ) -> Result<Option<Self::Item>> { ... }
    fn get_next(
        &mut self,
        key: &Key,
        direction: Direction,
    ) -> Result<Option<Self::Item>> { ... }
}
Expand description

A cursor that has keys bound to each position in ascending order. Making this generic so that each Cursor may define multiple Keys.

Required Methods§

Source

fn get_key(&self) -> Option<Key>

Get the key of the current position.

Provided Methods§

Source

fn jump_near_key(&mut self, _key: &Key, _direction: Direction)

Used by jump_to_keys with same parameters. Should be overridden to make jump_to_key more efficient by moving cursor near the key. Notice that jump_to_key should work as long as keys are monotonic in same order as offsets, even if this function does nothing.

Source

fn jump_to_key(&mut self, key: &Key, direction: Direction) -> Result<bool>

Move the cursor to the closest valid pos to the given key in the given direction. Return if the key at the final pos satisfies the ordering requirement. For example, for a list of int keys: [3, 7, 8, 12, 19], jumping to key 9 forward moves cursor to index 3 because 12 is the smallest int greater than 9 in the list. Jumping to key 0 reverse moves cursor to index 0 and returns false because no key is smaller than 3.

Source

fn get_near( &mut self, key: &Key, preferred_direction: Direction, ) -> Result<Option<Self::Item>>

Convenient function to jump to a key and get the closest valid item to the key. Preference is given to the specified direction. Returns None only if there are no keys at all.

For example, for a list of int keys: [3, 7, 8, 12, 19], cursor.get_near(0, Direction::Reverse) will jump cursor to 3 and return 3.

Source

fn get_next( &mut self, key: &Key, direction: Direction, ) -> Result<Option<Self::Item>>

Convenient function to jump to a key and get the closest valid item that is at key or in the given direction of key. Returns None if no such key exists.

For example, for a list of int keys: [3, 7, 8, 12, 19], cursor.get_next(0, Direction::Reverse) will return Ok(None).

Implementors§

Source§

impl KeyedCursor<u64> for StoreCursor

StoreCursor has each cursor position bound to a SystemTime in monotonic order. This allows moving the cursor relative to SystemTime instances.