Struct hashbag::HashBag

source ·
pub struct HashBag<T, S = RandomState> { /* private fields */ }
Expand description

A hash bag implemented as a HashMap where the value is usize.

A bag, unlike a set, allows duplicate values, and keeps track of how many duplicates each value holds. This type of collection is often referred to as an unordered multiset.

As with the HashMap type, a HashBag requires that the elements implement the Eq and Hash traits. This can frequently be achieved by using #[derive(PartialEq, Eq, Hash)]. If you implement these yourself, it is important that the following property holds:

k1 == k2 -> hash(k1) == hash(k2)

In other words, if two keys are equal, their hashes must be equal.

It is a logic error for an item to be modified in such a way that the item’s hash, as determined by the Hash trait, or its equality, as determined by the Eq trait, changes while it is in the bag.

§Examples

use hashbag::HashBag;
// Type inference lets us omit an explicit type signature (which
// would be `HashBag<String>` in this example).
let mut books = HashBag::new();

// Add some books.
// Since we are a library, we have many copies.
books.insert("A Dance With Dragons".to_string());
books.insert("To Kill a Mockingbird".to_string());
books.insert("To Kill a Mockingbird".to_string());
books.insert("The Odyssey".to_string());
books.insert("The Odyssey".to_string());
books.insert("The Odyssey".to_string());
books.insert("The Great Gatsby".to_string());
books.insert("The Great Gatsby".to_string());
books.insert("The Great Gatsby".to_string());
books.insert("The Great Gatsby".to_string());

// When we count the number of books, duplicates are included.
assert_eq!(books.len(), 10);

// Check for a specific one.
if books.contains("The Winds of Winter") == 0 {
    println!("We have {} books, but The Winds of Winter ain't one.",
             books.len());
}

// Remove a book.
let had_copies = books.remove("The Odyssey");
// Remove returns how many copies of that book we had.
assert_eq!(had_copies, 3);

// Iterate over everything.
// Duplicates will be listed multiple times.
for book in &books {
    println!("{}", book);
}

// Iterate over each distinct book.
for (book, copies) in books.set_iter() {
    println!("{} ({} copies)", book, copies);
}

// Extract the books and their counts.
for (book, copies) in books {
    println!("{} ({} copies)", book, copies);
}

The easiest way to use HashBag with a custom type is to derive Eq and Hash. We must also derive PartialEq, this will in the future be implied by Eq.

use hashbag::HashBag;
#[derive(Hash, Eq, PartialEq, Debug, Clone)]
struct Viking {
    name: String,
    power: usize,
}

let mut vikings = HashBag::new();

vikings.insert(Viking { name: "Einar".to_string(), power: 9 });
vikings.insert(Viking { name: "Einar".to_string(), power: 9 });
vikings.insert(Viking { name: "Olaf".to_string(), power: 4 });
vikings.insert(Viking { name: "Olaf".to_string(), power: 5 });
vikings.insert(Viking { name: "Harald".to_string(), power: 8 });

// Use derived implementation to print the vikings.
// Notice that all duplicates are printed.
for v in &vikings {
    println!("{:?}", v);
}

// Since the derived implementation compares all the fields,
// vikings that share a name but not a power are not duplicates.
for (v, n) in vikings.set_iter() {
    println!("{:?} ({} of them!)", v, n);
}

// HashBags themselves can also be compared for equality,
// and will do so by considering both the values and their counts.
let mut vikings2 = vikings.clone();
assert_eq!(vikings, vikings2);
let fallen = vikings.iter().next().unwrap();
vikings2.remove(fallen);
assert_ne!(vikings, vikings2);
vikings2.insert(Viking { name: "Snorre".to_string(), power: 1 });
assert_ne!(vikings, vikings2);

A HashBag with fixed list of elements can be initialized from an array:

use hashbag::HashBag;

let mut viking_names: HashBag<&'static str> =
    [ "Einar", "Olaf", "Harald" ].iter().cloned().collect();
// use the values stored in the bag

You can also extend the bag easily:

use hashbag::HashBag;

let mut vikings: HashBag<String> = HashBag::new();
vikings.extend(std::iter::once("Snorre".to_string()));
assert_eq!(vikings.contains("Snorre"), 1);

// You can extend with many instances at once:
vikings.extend(std::iter::once(("Snorre".to_string(), 4)));
assert_eq!(vikings.contains("Snorre"), 5);

// Extension also works with reference iterators if the type is Clone:
let einar = String::from("Einar");
vikings.extend(std::iter::once(&einar));
assert_eq!(vikings.contains(&einar), 1);

// And extend with many instances at once:
vikings.extend(std::iter::once((&einar, 4)));
assert_eq!(vikings.contains(&einar), 5);

Implementations§

source§

impl<T: Hash + Eq> HashBag<T, RandomState>

source

pub fn new() -> HashBag<T, RandomState>

Creates an empty HashBag.

The hash bag is initially created with a capacity of 0, so it will not allocate until it is first inserted into.

§Examples
use hashbag::HashBag;
let bag: HashBag<i32> = HashBag::new();
source

pub fn with_capacity(capacity: usize) -> HashBag<T, RandomState>

Creates an empty HashBag with the specified capacity.

The hash bag will be able to hold at least capacity distinct values without reallocating. If capacity is 0, the hash bag will not allocate.

§Examples
use hashbag::HashBag;
let bag: HashBag<i32> = HashBag::with_capacity(10);
assert!(bag.capacity() >= 10);
source§

impl<T, S> HashBag<T, S>

source

pub fn capacity(&self) -> usize

Returns the number of distinct values the bag can hold without reallocating.

§Examples
use hashbag::HashBag;
let bag: HashBag<i32> = HashBag::with_capacity(100);
assert!(bag.capacity() >= 100);
source

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

An iterator visiting all elements in arbitrary order.

The iterator element type is &'a T. Duplicates are yielded as many times as they appear in the bag.

§Examples
use hashbag::HashBag;
let mut bag = HashBag::new();
bag.insert("a");
bag.insert("b");
bag.insert("b");

// Will print in an arbitrary order.
// b will be printed twice.
for x in bag.iter() {
    println!("{}", x);
}
source

pub fn set_iter(&self) -> SetIter<'_, T>

An iterator visiting all distinct elements in arbitrary order.

The iterator element type is (&'a T, usize). Duplicated values are yielded once along with a count of the number of occurrences.

§Examples
use hashbag::HashBag;
let mut bag = HashBag::new();
bag.insert("a");
bag.insert("b");
bag.insert("b");

// Will print in an arbitrary order.
for (x, n) in bag.set_iter() {
    println!("{} {}", x, n);
}
source

pub fn len(&self) -> usize

Returns the number of elements in the bag.

Duplicates are counted.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();
assert_eq!(bag.len(), 0);
bag.insert(1);
assert_eq!(bag.len(), 1);
bag.insert(1);
assert_eq!(bag.len(), 2);
source

pub fn set_len(&self) -> usize

Returns the number of elements in the bag.

Duplicates are not counted.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();
assert_eq!(bag.set_len(), 0);
bag.insert(1);
assert_eq!(bag.set_len(), 1);
bag.insert(1);
assert_eq!(bag.set_len(), 1);
source

pub fn is_empty(&self) -> bool

Returns true if the bag contains no elements.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();
assert!(bag.is_empty());
bag.insert(1);
assert!(!bag.is_empty());
source

pub fn drain(&mut self) -> Drain<'_, T>

Clears the bag, returning all elements in an iterator.

Duplicates appear only in the count yielded for each element.

§Examples
use hashbag::HashBag;

let mut bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
assert!(!bag.is_empty());

// prints
//   1 1
//   2 1
//   3 2
// in an arbitrary order
for (i, n) in bag.drain() {
    println!("{} {}", i, n);
}

assert!(bag.is_empty());
source

pub fn clear(&mut self)

Clears the bag, removing all values.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();
bag.insert(1);
bag.clear();
assert!(bag.is_empty());
source§

impl<T, S> HashBag<T, S>
where T: Eq + Hash, S: BuildHasher,

source

pub fn with_hasher(hash_builder: S) -> HashBag<T, S>

Creates a new empty hash bag which will use the given hasher to hash keys.

The hash bag is also created with the default initial capacity.

Warning: hasher is normally randomly generated, and is designed to allow HashBags to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.

§Examples
use hashbag::HashBag;
use std::collections::hash_map::RandomState;

let s = RandomState::new();
let mut bag = HashBag::with_hasher(s);
bag.insert(2);
source

pub fn with_capacity_and_hasher( capacity: usize, hash_builder: S ) -> HashBag<T, S>

Creates an empty HashBag with the specified capacity, using hasher to hash the keys.

The hash bag will be able to hold at least capacity distinct values without reallocating. If capacity is 0, the hash bag will not allocate.

Warning: hasher is normally randomly generated, and is designed to allow HashBags to be resistant to attacks that cause many collisions and very poor performance. Setting it manually using this function can expose a DoS attack vector.

§Examples
use hashbag::HashBag;
use std::collections::hash_map::RandomState;

let s = RandomState::new();
let mut bag = HashBag::with_capacity_and_hasher(10, s);
bag.insert(1);
source

pub fn hasher(&self) -> &S

Returns a reference to the bag’s BuildHasher.

§Examples
use hashbag::HashBag;
use std::collections::hash_map::RandomState;

let hasher = RandomState::new();
let bag: HashBag<i32> = HashBag::with_hasher(hasher);
let hasher: &RandomState = bag.hasher();
source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more distinct values to be inserted in the HashBag. The collection may reserve more space to avoid frequent reallocations.

§Panics

Panics if the new allocation size overflows usize.

§Examples
use hashbag::HashBag;
let mut bag: HashBag<i32> = HashBag::new();
bag.reserve(10);
assert!(bag.capacity() >= 10);
source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the ba as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::with_capacity(100);
bag.insert(1);
bag.insert(2);
assert!(bag.capacity() >= 100);
bag.shrink_to_fit();
assert!(bag.capacity() >= 2);
source

pub fn contains<Q>(&self, value: &Q) -> usize
where T: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns the number of instances of value in the bag.

The value may be any borrowed form of the bag’s value type, but Hash and Eq on the borrowed form must match those for the value type.

§Examples
use hashbag::HashBag;

let bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
assert_eq!(bag.contains(&1), 1);
assert_eq!(bag.contains(&3), 2);
assert_eq!(bag.contains(&4), 0);
source

pub fn get<Q>(&self, value: &Q) -> Option<(&T, usize)>
where T: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value in the bag, if any, that is equal to the given value, along with its number of occurrences.

The value may be any borrowed form of the bag’s value type, but Hash and Eq on the borrowed form must match those for the value type.

§Examples
use hashbag::HashBag;

let bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
assert_eq!(bag.get(&2), Some((&2, 1)));
assert_eq!(bag.get(&3), Some((&3, 2)));
assert_eq!(bag.get(&4), None);
source

pub fn entry(&mut self, value: T) -> Entry<'_, T, S>

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

§Examples
use hashbag::HashBag;

let mut bag: HashBag<char> = ['a'].iter().cloned().collect();
let entry = bag.entry('a').and_modify(|n| *n += 1).or_insert();
assert_eq!(bag.get(&'a'), Some((&'a', 2)));
let entry = bag.entry('b').and_modify(|n| *n += 1).or_insert();
assert_eq!(bag.get(&'b'), Some((&'b', 1)));
let entry = bag.entry('c').and_modify(|n| *n += 1).or_insert_many(7);
assert_eq!(bag.get(&'c'), Some((&'c', 7)));
source

pub fn insert(&mut self, value: T) -> usize

Adds a value to the bag.

The number of occurrences of the value previously in the bag is returned.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();

assert_eq!(bag.insert(2), 0);
assert_eq!(bag.insert(2), 1);
assert_eq!(bag.insert(2), 2);
assert_eq!(bag.set_len(), 1);
assert_eq!(bag.len(), 3);
source

pub fn insert_many(&mut self, value: T, count: usize) -> usize

Adds multiple occurrences of a value to the bag.

The number of occurrences of the value previously in the bag is returned.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();

assert_eq!(bag.insert_many(2, 1), 0);
assert_eq!(bag.insert_many(2, 2), 1);
assert_eq!(bag.insert_many(2, 4), 3);
assert_eq!(bag.set_len(), 1);
assert_eq!(bag.len(), 7);
source

pub fn replace(&mut self, value: T) -> usize

Adds a value to the bag, replacing all existing occurrences, if any, that equal the given one.

The number of occurrences of the value previously in the bag is returned.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();
bag.insert(Vec::<i32>::new());
bag.insert(Vec::<i32>::new());
assert_eq!(bag.contains(&[][..]), 2);
assert_eq!(bag.get(&[][..]).unwrap().0.capacity(), 0);

bag.replace(Vec::with_capacity(10));
assert_eq!(bag.contains(&[][..]), 1);
assert_eq!(bag.get(&[][..]).unwrap().0.capacity(), 10);
source

pub fn remove<Q>(&mut self, value: &Q) -> usize
where T: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes a value from the bag.

The number of occurrences of the value previously in the bag is returned.

The value may be any borrowed form of the bag’s value type, but Hash and Eq on the borrowed form must match those for the value type.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();

bag.insert_many('x', 2);
assert_eq!(bag.contains(&'x'), 2);
assert_eq!(bag.remove(&'x'), 2);
assert_eq!(bag.contains(&'x'), 1);
assert_eq!(bag.remove(&'x'), 1);
assert_eq!(bag.contains(&'x'), 0);
assert_eq!(bag.remove(&'x'), 0);
source

pub fn remove_up_to<Q>(&mut self, value: &Q, quantity: usize) -> usize
where T: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes multiple of a value from the bag. If quantity is greater than the number of occurences, zero occurances will remain.

The number of occurrences of the value currently in the bag is returned.

The value may be any borrowed form of the bag’s value type, but Hash and Eq on the borrowed form must match those for the value type.

§Examples
use hashbag::HashBag;

let mut bag = HashBag::new();

bag.insert_many('x', 10);
assert_eq!(bag.contains(&'x'), 10);
assert_eq!(bag.remove_up_to(&'x', 3), 7);
assert_eq!(bag.contains(&'x'), 7);
assert_eq!(bag.remove_up_to(&'x', 10), 0);
source

pub fn outer_join<'a, OtherS>( &'a self, other: &'a HashBag<T, OtherS> ) -> impl Iterator<Item = (&'a T, usize, usize)>
where OtherS: BuildHasher,

Returns an iterator over all of the elements that are in self or other. The iterator also yields the respective counts in self and other in that order. Elements that are in self are yielded before any elements that are exclusively in other. Each distinct element is yielded only once.

§Examples
use hashbag::HashBag;
use std::collections::HashSet;
use std::iter::FromIterator;

let a: HashBag<_> = "hash".chars().collect();
let b: HashBag<_> = "math".chars().collect();
let expected: HashSet<_> = HashSet::from_iter([(&'h', 2, 1), (&'a', 1, 1), (&'s', 1, 0), (&'m', 0, 1), (&'t', 0, 1)]);
let actual: HashSet<_> = a.outer_join(&b).collect();
assert_eq!(expected, actual);
source

pub fn difference<'a, OtherS>( &'a self, other: &'a HashBag<T, OtherS> ) -> impl Iterator<Item = (&'a T, usize)>
where OtherS: BuildHasher,

Returns an iterator over all the elements that are in self with a higher occurrence count than in other. The count in the returned iterator represents how many more of a given element are in self than other.

§Examples
use hashbag::HashBag;
use std::collections::HashSet;
use std::iter::FromIterator;

let a: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
let b: HashBag<_> = [2, 3].iter().cloned().collect();
let expected: HashSet<_> = HashSet::from_iter([(&1, 1), (&3, 1)]);
let actual: HashSet<_> = a.difference(&b).collect();
assert_eq!(expected, actual);
source

pub fn signed_difference<'a, OtherS>( &'a self, other: &'a HashBag<T, OtherS> ) -> impl Iterator<Item = (&'a T, isize)>
where OtherS: BuildHasher,

Returns an iterator over all the elements that are in self or other. The iterator also yields the difference in counts between self and other.

Unlike ‘difference’ which only yields elements that have a higher count in self than in other, this iterator yields all elements that are in either of the HashBags. Elements that have a higher count in other than in self (including elements that are not in self) will have a negative count.

If the difference can be represented as an isize, then it will be. Otherwise, the difference will be clamped to isize::MIN/isize::MAX, thus keeping the sign of the difference, and as much of the magnitude as possible.

§Examples
use hashbag::HashBag;
use std::collections::HashSet;
use std::iter::FromIterator;

let a: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
let b: HashBag<_> = [2, 3, 4, 4].iter().cloned().collect();
let expected: HashSet<_> = HashSet::from_iter([(&1, 1), (&2, 0), (&3, 1), (&4, -2)]);
let actual: HashSet<_> = a.signed_difference(&b).collect();
assert_eq!(expected, actual);
source

pub fn not_in<'a, OtherS>( &'a self, other: &'a HashBag<T, OtherS> ) -> impl Iterator<Item = (&'a T, usize)>
where OtherS: BuildHasher,

Returns an iterator over all of the elements that are in self but not in other.

§Examples
use hashbag::HashBag;
use std::collections::HashSet;
use std::iter::FromIterator;

let a: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
let b: HashBag<_> = [2, 3].iter().cloned().collect();
let expected: HashSet<_> = HashSet::from_iter([(&1, 1)]);
let actual: HashSet<_> = a.not_in(&b).collect();
assert_eq!(expected, actual);
source

pub fn try_take<Q>(&mut self, value: &Q) -> Result<T, Option<(&T, usize)>>
where T: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes a value that is equal to the given one, and returns it if it was the last.

If the matching value is not the last, a reference to the remainder is given, along with the number of occurrences prior to the removal.

The value may be any borrowed form of the bag’s value type, but Hash and Eq on the borrowed form must match those for the value type.

§Examples
use hashbag::HashBag;

let mut bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
assert_eq!(bag.try_take(&2), Ok(2));
assert_eq!(bag.try_take(&3), Err(Some((&3, 2))));
assert_eq!(bag.try_take(&3), Ok(3));
assert_eq!(bag.try_take(&4), Err(None));
source

pub fn take_all<Q>(&mut self, value: &Q) -> Option<(T, usize)>
where T: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes and returns all occurrences of the value, if any, that is equal to the given one.

The value may be any borrowed form of the bag’s value type, but Hash and Eq on the borrowed form must match those for the value type.

§Examples
use hashbag::HashBag;

let mut bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
assert_eq!(bag.take_all(&2), Some((2, 1)));
assert_eq!(bag.take_all(&3), Some((3, 2)));
assert_eq!(bag.take_all(&2), None);
assert_eq!(bag.take_all(&3), None);
source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&T, usize) -> usize,

Retains only the values specified by the predicate.

In other words, for each value v retain only f(&v) occurrences.

§Examples
use hashbag::HashBag;

let xs = [0,0,0,0,0,1,1,1,1,2,2,2,3,3,4];
let mut bag: HashBag<i32> = xs.iter().cloned().collect();
bag.retain(|&k, _| k as usize);
assert_eq!(bag.set_len(), 4); // >= 1 of all but value 0
assert_eq!(bag.len(), 6);
assert_eq!(bag.contains(&0), 0);
assert_eq!(bag.contains(&1), 1);
assert_eq!(bag.contains(&2), 2);
assert_eq!(bag.contains(&3), 2);
assert_eq!(bag.contains(&4), 1);

Trait Implementations§

source§

impl<T: Clone + Hash, S: Clone + BuildHasher> Clone for HashBag<T, S>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

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

Performs copy-assignment from source. Read more
source§

impl<T> Debug for HashBag<T>
where T: Debug,

source§

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

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

impl<T, S> Default for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher + Default,

source§

fn default() -> Self

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

impl<'a, T, S> Extend<&'a T> for HashBag<T, S>
where T: 'a + Eq + Hash + Clone, S: BuildHasher,

source§

fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)

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<'a, T, S> Extend<(&'a T, usize)> for HashBag<T, S>
where T: 'a + Eq + Hash + Clone, S: BuildHasher,

source§

fn extend<I: IntoIterator<Item = (&'a T, usize)>>(&mut self, iter: I)

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<T, S> Extend<(T, usize)> for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher,

source§

fn extend<I: IntoIterator<Item = (T, usize)>>(&mut self, iter: I)

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<T, S> Extend<T> for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher,

source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

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<T, S> FromIterator<(T, usize)> for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher + Default,

source§

fn from_iter<I: IntoIterator<Item = (T, usize)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T, S> FromIterator<T> for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher + Default,

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a, T, S> IntoIterator for &'a HashBag<T, S>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T, S> IntoIterator for HashBag<T, S>

§

type Item = (T, usize)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more
source§

impl<T, S> PartialEq for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher,

source§

fn eq(&self, other: &Self) -> 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<T, S> Eq for HashBag<T, S>
where T: Eq + Hash, S: BuildHasher,

Auto Trait Implementations§

§

impl<T, S> RefUnwindSafe for HashBag<T, S>

§

impl<T, S> Send for HashBag<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for HashBag<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for HashBag<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for HashBag<T, S>
where S: UnwindSafe, T: 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.