Skip to main content

BTree

Struct BTree 

Source
pub struct BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,
{ /* private fields */ }
Expand description

The main data structure for the B-tree algorithm.

Implementations§

Source§

impl<TKey, TValue, TConfig> BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,

Source

pub fn new() -> Self
where TConfig: Default,

Creates a new BTree with the default configuration.

Note: this method doesn’t allocate anything.

Source

pub fn with_config(config: TConfig) -> Self

Creates a new BTree with the specified configuration.

Note: this method doesn’t allocate anything.

Source

pub const fn len(&self) -> Length

Returns the number of key-value pairs in the BTree.

Source§

impl<TKey, TValue, TConfig> BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,

Source

pub fn try_insert_or_update( &mut self, key: TKey, adder: impl FnOnce() -> TValue, updater: impl FnOnce(&mut TValue), ) -> Result<&mut TValue, BTreeError>

Inserts a (key, adder()) pair into the tree if it doesn’t exist, or updates the value with update(value) call.

§Notes
  • If the key already exists, then this method discards key.
  • This method guarantees that either adder or updater will be called, but not both.
§Errors

See BTreeError for details.

Source

pub fn try_insert( &mut self, key: TKey, value: TValue, ) -> Result<Option<TValue>, BTreeError>

Inserts a (key, value) pair into the tree.

Returns None if the key was not already present, or the previous value if it was.

§Notes

This method discards key if it already exists.

§Errors

See BTreeError for details.

Source§

impl<TKey, TValue, TConfig> BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,

Source

pub fn iter(&self) -> impl Iterator<Item = KVP<&TKey, &TValue>>

Iterates over the tree in ascending order.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = KVP<&TKey, &mut TValue>>

Iterates over the tree in ascending order.

Source§

impl<TKey, TValue, TConfig> BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<KVP<TKey, TValue>>
where TKey: Borrow<Q>, Q: Ord + ?Sized,

Removes a key-value pair from the BTree.

Returns the removed key-value pair if the key was present, otherwise None.

Source§

impl<TKey, TValue, TConfig> BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,

Source

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

Returns the key-value pair with key matching the given key. Return None if the key is not present in the BTree.

Trait Implementations§

Source§

impl<TKey, TValue, TConfig> Clone for BTree<TKey, TValue, TConfig>
where TKey: Ord + TryClone, TValue: TryClone, TConfig: BTreeConfig + TryClone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<TKey, TValue: Debug, TConfig> Debug for BTree<TKey, TValue, TConfig>
where TKey: Ord + Debug, TConfig: BTreeConfig + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TKey, TValue, TConfig> Default for BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig + Default,

Source§

fn default() -> Self

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

impl<'de, TKey, TValue, TConfig> Deserialize<'de> for BTree<TKey, TValue, TConfig>
where TKey: Ord + Deserialize<'de>, TValue: Deserialize<'de>, TConfig: BTreeConfig + Default,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<TKey, TValue, TConfig> Drop for BTree<TKey, TValue, TConfig>
where TKey: Ord, TConfig: BTreeConfig,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<TKey, TValue, TConfig> Eq for BTree<TKey, TValue, TConfig>
where TKey: Ord, TValue: Eq, TConfig: BTreeConfig,

Source§

impl<TKey, TValue, TConfig> Hash for BTree<TKey, TValue, TConfig>
where TKey: Ord + Hash, TValue: Hash, TConfig: BTreeConfig,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<TKey, TValue, TConfig> PartialEq for BTree<TKey, TValue, TConfig>
where TKey: Ord, TValue: PartialEq, TConfig: BTreeConfig,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<TKey, TValue, TConfig> ReprC for BTree<TKey, TValue, TConfig>
where TKey: Ord + ReprC, TValue: ReprC, TConfig: BTreeConfig,

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<TKey, TValue, TConfig> Send for BTree<TKey, TValue, TConfig>
where TKey: Ord + Send, TValue: Send, TConfig: BTreeConfig + Send,

Source§

impl<TKey, TValue, TConfig> Serialize for BTree<TKey, TValue, TConfig>
where TKey: Ord + Serialize, TValue: Serialize, TConfig: BTreeConfig,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<TKey, TValue, TConfig> Sync for BTree<TKey, TValue, TConfig>
where TKey: Ord + Sync, TValue: Sync, TConfig: BTreeConfig + Sync,

Source§

impl<TKey, TValue, TConfig> TryClone for BTree<TKey, TValue, TConfig>
where TKey: Ord + TryClone, TValue: TryClone, TConfig: BTreeConfig + TryClone,

Source§

type Error = BTreeTryCloneError

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Tries to clone the type. Read more

Auto Trait Implementations§

§

impl<TKey, TValue, TConfig> Freeze for BTree<TKey, TValue, TConfig>
where TConfig: Freeze,

§

impl<TKey, TValue, TConfig> RefUnwindSafe for BTree<TKey, TValue, TConfig>
where TConfig: RefUnwindSafe, TKey: RefUnwindSafe, TValue: RefUnwindSafe,

§

impl<TKey, TValue, TConfig> Unpin for BTree<TKey, TValue, TConfig>
where TConfig: Unpin, TKey: Unpin, TValue: Unpin,

§

impl<TKey, TValue, TConfig> UnsafeUnpin for BTree<TKey, TValue, TConfig>
where TConfig: UnsafeUnpin,

§

impl<TKey, TValue, TConfig> UnwindSafe for BTree<TKey, TValue, TConfig>
where TConfig: UnwindSafe, TKey: UnwindSafe, TValue: 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.