Skip to main content

RawSharedIter

Struct RawSharedIter 

Source
pub struct RawSharedIter<'t, K, V, const IC: usize, const LC: usize> { /* private fields */ }
Expand description

Raw shared iterator over the entries of the tree.

Implementations§

Source§

impl<'t, K: Clone + Ord, V, const IC: usize, const LC: usize> RawSharedIter<'t, K, V, IC, LC>

Source

pub fn seek<Q>(&mut self, key: &Q)
where K: Borrow<Q> + Ord, Q: ?Sized + Ord,

Sets the iterator cursor immediately before the position for this key.

Seeks to the position even though no value associated with the key exists on the tree.

A subsequent call of RawSharedIter::next should return the entry associated with this key or the one immediately following it.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

tree.insert(2, "b");

let mut iter = tree.raw_iter();

iter.seek(&2);
assert_eq!(iter.next(), Some((&2, &"b")));

iter.seek(&1);
assert_eq!(iter.next(), Some((&2, &"b")));

iter.seek(&3);
assert_eq!(iter.next(), None);
Source

pub fn seek_for_prev<Q>(&mut self, key: &Q)
where K: Borrow<Q> + Ord, Q: ?Sized + Ord,

Sets the iterator cursor immediately after the position for this key.

Seeks to the position even though no value associated with the key exists on the tree.

A subsequent call of RawSharedIter::prev should return the entry associated with this key or the one immediately preceding it.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

tree.insert(2, "b");

let mut iter = tree.raw_iter();

iter.seek_for_prev(&2);
assert_eq!(iter.prev(), Some((&2, &"b")));

iter.seek_for_prev(&3);
assert_eq!(iter.prev(), Some((&2, &"b")));

iter.seek_for_prev(&1);
assert_eq!(iter.prev(), None);
Source

pub fn seek_exact<Q>(&mut self, key: &Q) -> bool
where K: Borrow<Q> + Ord, Q: ?Sized + Ord,

Sets the iterator cursor immediately before the position for this key, returning true if the next entry matches the provided key.

A subsequent call of RawSharedIter::next should return the entry associated with this key if the method returned true.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

tree.insert(2, "b");

let mut iter = tree.raw_iter();

assert_eq!(iter.seek_exact(&2), true);
assert_eq!(iter.next(), Some((&2, &"b")));

assert_eq!(iter.seek_exact(&1), false);
assert_eq!(iter.next(), Some((&2, &"b")));

assert_eq!(iter.seek_exact(&3), false);
assert_eq!(iter.next(), None);
Source

pub fn seek_to_first(&mut self)

Sets the iterator cursor immediately before the position for the first key in the tree.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

let mut iter = tree.raw_iter();

iter.seek_to_first();
assert_eq!(iter.next(), None);

// Calling insert on the tree while holding an iterator
// in the same thread may deadlock, so we drop here
drop(iter);

tree.insert(2, "b");

let mut iter = tree.raw_iter();

iter.seek_to_first();
assert_eq!(iter.next(), Some((&2, &"b")));
Source

pub fn seek_to_last(&mut self)

Sets the iterator cursor immediately after the position for the last key in the tree.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

let mut iter = tree.raw_iter();

iter.seek_to_last();
assert_eq!(iter.prev(), None);

// Calling insert on the tree while holding an iterator
// in the same thread may deadlock, so we drop here
drop(iter);

tree.insert(2, "b");

let mut iter = tree.raw_iter();

iter.seek_to_last();
assert_eq!(iter.prev(), Some((&2, &"b")));
Source

pub fn next(&mut self) -> Option<(&K, &V)>

Returns the next entry from the current cursor position.

If the cursor was not seeked to any position this will always return None. This behavior may change in the future.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

tree.insert(2, "b");

let mut iter = tree.raw_iter();

iter.seek_to_first();

assert_eq!(iter.next(), Some((&2, &"b")));
assert_eq!(iter.next(), None);
Source

pub fn prev(&mut self) -> Option<(&K, &V)>

Returns the previous entry from the current cursor position.

If the cursor was not seeked to any position this will always return None. This behavior may change in the future.

§Examples

Basic usage:

use bplustree::BPlusTree;

let tree = BPlusTree::new();

tree.insert(2, "b");

let mut iter = tree.raw_iter();

iter.seek_to_last();

assert_eq!(iter.prev(), Some((&2, &"b")));
assert_eq!(iter.prev(), None);

Auto Trait Implementations§

§

impl<'t, K, V, const IC: usize, const LC: usize> Freeze for RawSharedIter<'t, K, V, IC, LC>

§

impl<'t, K, V, const IC: usize, const LC: usize> !RefUnwindSafe for RawSharedIter<'t, K, V, IC, LC>

§

impl<'t, K, V, const IC: usize, const LC: usize> !Send for RawSharedIter<'t, K, V, IC, LC>

§

impl<'t, K, V, const IC: usize, const LC: usize> !Sync for RawSharedIter<'t, K, V, IC, LC>

§

impl<'t, K, V, const IC: usize, const LC: usize> Unpin for RawSharedIter<'t, K, V, IC, LC>

§

impl<'t, K, V, const IC: usize, const LC: usize> UnsafeUnpin for RawSharedIter<'t, K, V, IC, LC>

§

impl<'t, K, V, const IC: usize, const LC: usize> !UnwindSafe for RawSharedIter<'t, K, V, IC, LC>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.