Struct pfx::map::PrefixTreeMap

source ·
pub struct PrefixTreeMap<K, V> { /* private fields */ }
Expand description

An ordered map from byte strings to arbitrary values, based on a prefix tree.

Implementations§

source§

impl<K, V> PrefixTreeMap<K, V>

source

pub const fn new() -> Self

Creates an empty map. The same as Default.

source

pub const fn len(&self) -> usize

Returns the number of entries (key-value pairs) in the map.

source

pub const fn is_empty(&self) -> bool

Returns true if and only if this map contains no key-value pairs.

source

pub fn get_entry<Q>(&self, key: &Q) -> Option<(&K, &V)>
where Q: ?Sized + AsRef<[u8]>,

Return a reference to the original key and value, if found.

source

pub fn get_entry_mut<Q>(&mut self, key: &Q) -> Option<(&K, &mut V)>
where Q: ?Sized + AsRef<[u8]>,

Return a reference to the original key and a mutable reference to the value, if found.

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where Q: ?Sized + AsRef<[u8]>,

Return a reference to the value, if found.

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where Q: ?Sized + AsRef<[u8]>,

Return a mutable reference to the value, if found.

source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: ?Sized + AsRef<[u8]>,

Returns true if and only if the given key is found in the map.

source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where Q: ?Sized + AsRef<[u8]>,

If the key exists in the map, return the original key and the correpsonding value.

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: ?Sized + AsRef<[u8]>,

If the key exists in the map, return the corresponding value.

source

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

An iterator over pairs of references to keys and the corresponding values.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn into_keys(self) -> IntoKeys<K, V>

An iterator over the owned keys.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn keys(&self) -> Keys<'_, K, V>

An iterator over the borrowed keys.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn into_values(self) -> IntoValues<K, V>

An iterator over the owned values.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn values(&self) -> Values<'_, K, V>

An iterator over the borrowed values.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn into_prefix_iter<Q>(self, prefix: &Q) -> NodeIntoIter<K, V>
where Q: ?Sized + AsRef<[u8]>,

An iterator over owned key-value pairs of which the key starts with the given prefix.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn prefix_iter<Q>(&self, prefix: &Q) -> NodeIter<'_, K, V>
where Q: ?Sized + AsRef<[u8]>,

An iterator over borrowed key-value pairs of which the key starts with the given prefix.

Iteration proceeds in lexicographic order, as determined by the byte sequence of keys.

source

pub fn compact(&mut self)

Removes all internal nodes that do not contain an entry.

This is useful for freeing up memory and speeding up iteration after removing many key-value pairs from the map and/or after creating many spurious nodes using the entry API (by not inserting into the nodes created by .entry()).

source§

impl<K, V> PrefixTreeMap<K, V>
where K: AsRef<[u8]>,

source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Return an object representing the (vacant or occupied) node of the tree corresponding to the given key.

This always creates a new node, even if you don’t end up inserting into it. Avoid creating many spurious entries, or call PrefixTreeMap::compact to remove useless (empty) nodes.

source

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

Replaces and returns the previous value, if any.

This leaves the key in the map untouched if it already exists.

source

pub fn union<I>(self, other: I) -> Self
where I: IntoIterator<Item = (K, V)>,

Takes the union of self with another set of elements. Elements that already exist in self will be overwritten by other.

source

pub fn union_in_place<I>(&mut self, other: I)
where I: IntoIterator<Item = (K, V)>,

Takes the union of self with another set of elements. Elements that already exist in self will be overwritten by other.

source

pub fn intersection<I>(self, other: I) -> Self
where I: IntoIterator, I::Item: AsRef<[u8]>,

Takes the intersection of self with another set of elements. The intersection is solely based on the keys.

source

pub fn difference<I>(self, other: I) -> Self
where I: IntoIterator, I::Item: AsRef<[u8]>,

Removes the items corresponding to keys in other from self.

source

pub fn difference_in_place<I>(&mut self, other: I)
where I: IntoIterator, I::Item: AsRef<[u8]>,

Removes the items corresponding to keys in other from self.

source

pub fn symmetric_difference<I>(self, other: I) -> Self
where I: IntoIterator<Item = (K, V)>,

Add elements that are missing from self, and remove elements contained in self.

Containment is tested by comparing keys only. Values are not checked for equality.

source

pub fn symmetric_difference_in_place<I>(&mut self, other: I)
where I: IntoIterator<Item = (K, V)>,

Add elements that are missing from self, and remove elements contained in self.

Containment is tested by comparing keys only. Values are not checked for equality.

Trait Implementations§

source§

impl<I, K, V> BitAnd<I> for PrefixTreeMap<K, V>
where I: IntoIterator, I::Item: AsRef<[u8]>, K: AsRef<[u8]>,

Creates the intersection of self and other.

§

type Output = PrefixTreeMap<K, V>

The resulting type after applying the & operator.
source§

fn bitand(self, other: I) -> Self::Output

Performs the & operation. Read more
source§

impl<I, K, V> BitAndAssign<I> for PrefixTreeMap<K, V>
where I: IntoIterator, I::Item: AsRef<[u8]>, K: AsRef<[u8]>,

Creates the intersection of self and other.

source§

fn bitand_assign(&mut self, other: I)

Performs the &= operation. Read more
source§

impl<I, K, V> BitOr<I> for PrefixTreeMap<K, V>
where I: IntoIterator<Item = (K, V)>, K: AsRef<[u8]>,

Creates the union of self and other.

§

type Output = PrefixTreeMap<K, V>

The resulting type after applying the | operator.
source§

fn bitor(self, other: I) -> Self::Output

Performs the | operation. Read more
source§

impl<I, K, V> BitOrAssign<I> for PrefixTreeMap<K, V>
where I: IntoIterator<Item = (K, V)>, K: AsRef<[u8]>,

Creates the union of self and other.

source§

fn bitor_assign(&mut self, other: I)

Performs the |= operation. Read more
source§

impl<I, K, V> BitXor<I> for PrefixTreeMap<K, V>
where I: IntoIterator<Item = (K, V)>, K: AsRef<[u8]>,

Creates the symmetric difference of self and other.

§

type Output = PrefixTreeMap<K, V>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, other: I) -> Self::Output

Performs the ^ operation. Read more
source§

impl<I, K, V> BitXorAssign<I> for PrefixTreeMap<K, V>
where I: IntoIterator<Item = (K, V)>, K: AsRef<[u8]>,

Creates the symmetric difference of self and other.

source§

fn bitxor_assign(&mut self, other: I)

Performs the ^= operation. Read more
source§

impl<K: Clone, V: Clone> Clone for PrefixTreeMap<K, V>

source§

fn clone(&self) -> PrefixTreeMap<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: Debug, V: Debug> Debug for PrefixTreeMap<K, V>

source§

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

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

impl<K, V> Default for PrefixTreeMap<K, V>

source§

fn default() -> Self

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

impl<K, V> Extend<(K, V)> for PrefixTreeMap<K, V>
where K: AsRef<[u8]>,

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
source§

impl<K, V, const N: usize> From<[(K, V); N]> for PrefixTreeMap<K, V>
where K: AsRef<[u8]>,

source§

fn from(items: [(K, V); N]) -> Self

Converts to this type from the input type.
source§

impl<K, V> FromIterator<(K, V)> for PrefixTreeMap<K, V>
where K: AsRef<[u8]>,

source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
source§

impl<K: Hash, V: Hash> Hash for PrefixTreeMap<K, V>

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<K, V, Q> Index<&Q> for PrefixTreeMap<K, V>
where K: AsRef<[u8]>, Q: ?Sized + AsRef<[u8]>,

§

type Output = V

The returned type after indexing.
source§

fn index(&self, key: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'a, K, V> IntoIterator for &'a PrefixTreeMap<K, V>

§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> IntoIterator for PrefixTreeMap<K, V>

§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
§

type Item = (K, V)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K: Ord, V: Ord> Ord for PrefixTreeMap<K, V>

source§

fn cmp(&self, other: &PrefixTreeMap<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<K: PartialEq, V: PartialEq> PartialEq for PrefixTreeMap<K, V>

source§

fn eq(&self, other: &PrefixTreeMap<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: PartialOrd, V: PartialOrd> PartialOrd for PrefixTreeMap<K, V>

source§

fn partial_cmp(&self, other: &PrefixTreeMap<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K: Eq, V: Eq> Eq for PrefixTreeMap<K, V>

source§

impl<K, V> StructuralPartialEq for PrefixTreeMap<K, V>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V> UnwindSafe for PrefixTreeMap<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> 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,

§

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

§

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

§

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.