Trait CollectAHash

Source
pub trait CollectAHash: Iterator {
    // Provided methods
    fn collect_ahashmap_with<K, V>(
        self,
        capacity: impl FnOnce(usize) -> usize,
    ) -> AHashMap<K, V>
       where Self: Sized + Iterator<Item = (K, V)>,
             K: Hash + Eq { ... }
    fn collect_ahashmap_with_exact<K, V>(
        self,
        capacity: impl FnOnce(usize) -> usize,
    ) -> AHashMap<K, V>
       where Self: Sized + Iterator<Item = (K, V)>,
             K: Hash + Eq { ... }
    fn collect_ahashset_with<K>(
        self,
        capacity: impl FnOnce(usize) -> usize,
    ) -> AHashSet<K>
       where Self: Sized + Iterator<Item = K>,
             K: Hash + Eq { ... }
    fn collect_ahashset_with_exact<K>(
        self,
        capacity: impl FnOnce(usize) -> usize,
    ) -> AHashSet<K>
       where Self: Sized + Iterator<Item = K>,
             K: Hash + Eq { ... }
}
Available on crate feature ahash only.
Expand description

Trait for collecting items into AHashMap or AHashSet with a specified capacity.

Provided Methods§

Source

fn collect_ahashmap_with<K, V>( self, capacity: impl FnOnce(usize) -> usize, ) -> AHashMap<K, V>
where Self: Sized + Iterator<Item = (K, V)>, K: Hash + Eq,

Collects items into an AHashMap with a specified capacity.

§Example
use ahash::AHashMap;
use collect_with::CollectAHash;

let map =  ('a'..='i')
  .zip(1..=9)
  .collect_ahashmap_with(|u| u + 5);
assert_eq!(map.get(&'a'), Some(&1));
assert_eq!(map.len(), 9);
assert_eq!(map.capacity(), 14);
Source

fn collect_ahashmap_with_exact<K, V>( self, capacity: impl FnOnce(usize) -> usize, ) -> AHashMap<K, V>
where Self: Sized + Iterator<Item = (K, V)>, K: Hash + Eq,

Collects items into an AHashMap with an exact specified capacity.

§Example
use ahash::AHashMap;
use collect_with::CollectAHash;

let map = [(1, "a"), (2, "b"), (3, "c")]
  .into_iter()
  .collect_ahashmap_with_exact(|size_hint| size_hint);
assert_eq!(map.len(), 3);
Source

fn collect_ahashset_with<K>( self, capacity: impl FnOnce(usize) -> usize, ) -> AHashSet<K>
where Self: Sized + Iterator<Item = K>, K: Hash + Eq,

Collects items into an AHashSet with a specified capacity.

§Example
use ahash::AHashSet;
use collect_with::CollectAHash;

let set = (0..3)
  .collect_ahashset_with(|size_hint| size_hint);
assert_eq!(set.len(), 3);
Source

fn collect_ahashset_with_exact<K>( self, capacity: impl FnOnce(usize) -> usize, ) -> AHashSet<K>
where Self: Sized + Iterator<Item = K>, K: Hash + Eq,

Collects items into an AHashSet with an exact specified capacity.

§Example
use ahash::AHashSet;
use collect_with::CollectAHash;

let set = (0..3)
  .into_iter()
  .collect_ahashset_with_exact(|size_hint| size_hint);
assert_eq!(set.len(), 3);

Implementors§