Struct Llrb

Source
pub struct Llrb<K, V>
where K: Clone + Ord, V: Clone,
{ /* private fields */ }
Expand description

Llrb manage a single instance of in-memory index using left-leaning-red-black tree.

Implementations§

Source§

impl<K, V> Llrb<K, V>
where K: Clone + Ord, V: Clone,

Different ways to construct a new Llrb instance.

Source

pub fn new<S>(name: S) -> Llrb<K, V>
where S: AsRef<str>,

Create an empty instance of Llrb, identified by name. Applications can choose unique names.

Source§

impl<K, V> Llrb<K, V>
where K: Clone + Ord, V: Clone,

Maintenance API.

Source

pub fn id(&self) -> String

Identify this instance. Applications can choose unique names while creating Llrb instances.

Source

pub fn len(&self) -> usize

Return number of entries in this instance.

Source

pub fn is_empty(&self) -> bool

Check whether this index is empty.

Source

pub fn stats(&self) -> Stats

Return quickly with basic statisics, only entries() method is valid with this statisics.

Source§

impl<K, V> Llrb<K, V>
where K: Clone + Ord, V: Clone,

Write operations on Llrb instance.

Source

pub fn create(&mut self, key: K, value: V) -> Result<(), Error<K>>

Create a new {key, value} entry in the index. If key is already present return error.

Source

pub fn set(&mut self, key: K, value: V) -> Option<V>

Set value for key. If there is an existing entry for key, overwrite the old value with new value and return the old value.

Source

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

Delete key from this instance and return its value. If key is not present, then delete is effectively a no-op.

Source

pub fn validate(&self) -> Result<Stats, Error<K>>

Validate LLRB tree with following rules:

  • From root to any leaf, no consecutive reds allowed in its path.
  • Number of blacks should be same under left child and right child.
  • Make sure keys are in sorted order.

Additionally return full statistics on the tree. Refer to Stats for more information.

Source§

impl<K, V> Llrb<K, V>
where K: Clone + Ord, V: Clone,

Read operations on Llrb instance.

Source

pub fn get<Q>(&self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Get the value for key.

Source

pub fn random<R: Rng>(&self, rng: &mut R) -> Option<(K, V)>

Return a random entry from this index.

Source

pub fn iter(&self) -> Iter<'_, K, V>

Return an iterator over all entries in this instance.

Source

pub fn range<Q, R>(&self, range: R) -> Range<'_, K, V, R, Q>
where K: Borrow<Q>, R: RangeBounds<Q>, Q: Ord + ?Sized,

Range over all entries from low to high.

Source

pub fn reverse<R, Q>(&self, range: R) -> Reverse<'_, K, V, R, Q>
where K: Borrow<Q>, R: RangeBounds<Q>, Q: Ord + ?Sized,

Reverse range over all entries from high to low.

Trait Implementations§

Source§

impl<K, V> Clone for Llrb<K, V>
where K: Clone + Ord + Clone, V: Clone + Clone,

Source§

fn clone(&self) -> Llrb<K, V>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V> Extend<(K, V)> for Llrb<K, V>
where K: Clone + Ord, V: Clone,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (K, V)>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for Llrb<K, V>

§

impl<K, V> RefUnwindSafe for Llrb<K, V>

§

impl<K, V> Send for Llrb<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Llrb<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Llrb<K, V>

§

impl<K, V> UnwindSafe for Llrb<K, V>
where K: UnwindSafe, V: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.