Struct yadf::TreeBag

source ·
pub struct TreeBag<K, V>(/* private fields */);
Expand description

Ordered counter structure.

§Example :

use yadf::TreeBag;

let bag: TreeBag<i32, &str> = vec![
    (3, "hello world"),
    (3, "foobar"),
    (7, "fizz"),
    (7, "buzz"),
    (6, "rust"),
].into_iter().collect();

assert_eq!(bag[&3], ["hello world", "foobar"]);
assert_eq!(bag[&7], ["fizz", "buzz"]);
assert_eq!(bag[&6], ["rust"]);

Implementations§

source§

impl<K, V> TreeBag<K, V>

source

pub const fn duplicates(&self) -> Replicates<'_, K, V>

Provides a view only on the buckets containing more than one element.

source

pub const fn replicates(&self, factor: Factor) -> Replicates<'_, K, V>

Provides a view only on the buckets as constrained by the replication Factor.

source

pub const fn as_inner(&self) -> &BTreeMap<K, Vec<V>>

Borrows the backing BTreeMap of the bag.

source

pub fn as_inner_mut(&mut self) -> &mut BTreeMap<K, Vec<V>>

Mutably borrows the backing BTreeMap of the bag.

source

pub fn into_inner(self) -> BTreeMap<K, Vec<V>>

Consumes the wrapper TreeBag and returns the inner BTreeMap.

source

pub fn len(&self) -> usize

Returns the number of buckets in the bag.

source

pub fn is_empty(&self) -> bool

Returns true if the bag contains no elements.

source

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

Returns a reference to the bucket corresponding to the key.

source

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

Returns a mutable reference to the bucket corresponding to the key.

source

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

Gets the given key’s corresponding entry in the bag for in-place manipulation.

Trait Implementations§

source§

impl<K: Debug, V: Debug> Debug for TreeBag<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 TreeBag<K, V>

source§

fn default() -> Self

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

impl<K: Ord, V> Extend<(K, V)> for TreeBag<K, V>

source§

fn extend<I>(&mut self, key_value_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> From<BTreeMap<K, Vec<V>>> for TreeBag<K, V>

source§

fn from(btree: BTreeMap<K, Vec<V>>) -> Self

Build a TreeBag from a BTreeMap.

source§

impl<K: Ord, V> FromIterator<(K, V)> for TreeBag<K, V>

source§

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

Creates a value from an iterator. Read more
source§

impl<K, Q, V> Index<&Q> for TreeBag<K, V>
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

source§

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

Returns a reference to the value corresponding to the supplied key.

§Panics

Panics if the key is not present in the TreeBag.

§

type Output = Vec<V>

The returned type after indexing.
source§

impl<K, V> Serialize for TreeBag<K, V>
where K: Serialize, V: Serialize,

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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

§

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.