Struct Art

Source
pub struct Art<K, V> { /* private fields */ }
Expand description

Adaptive Radix Tree.

Radix tree is ordered according to key. Radix tree requires that key to be representable as comparable by sequence, e.g. key should implement Key trait which used to convert it to byte sequence.

This crate provides Key implementations for most commonly used data types:

  • unsigned integers(u8, u16, u32, u64, u128)
  • signed integers(i8, i16, i32, i64, i128)
  • usize
  • floating point numbers through Float32/Float64 types
  • ByteString for raw byte sequences. It can be used for ASCII strings(UTF-8 strings not supported now, they require additional library to convert into comparable byte sequence).

Implementations§

Source§

impl<K: Key, V> Art<K, V>

Source

pub fn new() -> Self

Create empty [ART] tree.

Source

pub fn insert(&mut self, key: K, value: V) -> bool

Insert key-value pair into tree.
Return true if key-value successfully inserted into tree, otherwise false if tree already contains same key.

Source

pub fn upsert(&mut self, key: K, value: V)

Insert key-value pair into tree. If key already exists in tree, existing value will be replaced, otherwise inserts new KV into tree.

Source

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

Remove value associated with key.
Returns Some(V) if key found in tree, otherwise None.

Source

pub fn get(&self, key: &K) -> Option<&V>

Get value associated with key.
Returns Some(V) if key found in tree, otherwise None.

Source

pub fn range( &self, range: impl RangeBounds<K>, ) -> impl DoubleEndedIterator<Item = (&K, &V)>
where K: Ord,

Execute tree range scan.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = (&K, &V)>
where K: Ord,

Returns tree iterator.

Trait Implementations§

Source§

impl<K: Key, V> Default for Art<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for Art<K, V>
where K: Freeze, V: Freeze,

§

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

§

impl<K, V> !Send for Art<K, V>

§

impl<K, V> !Sync for Art<K, V>

§

impl<K, V> Unpin for Art<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for Art<K, V>

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, 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.