[−][src]Struct flurry::HashSet
A concurrent hash set implemented as a HashMap
where the value is ()
.
Examples
use flurry::HashSet; // Initialize a new hash set. let books = HashSet::new(); let guard = books.guard(); // Add some books books.insert("Fight Club", &guard); books.insert("Three Men In A Raft", &guard); books.insert("The Book of Dust", &guard); books.insert("The Dry", &guard); // Check for a specific one. if !books.contains(&"The Drunken Botanist", &guard) { println!("We don't have The Drunken Botanist."); } // Remove a book. books.remove(&"Three Men In A Raft", &guard); // Iterate over everything. for book in books.iter(&guard) { println!("{}", book); }
Methods
impl<T> HashSet<T, DefaultHashBuilder>
[src]
pub fn new() -> Self
[src]
Creates an empty HashSet
.
The hash set is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Examples
use flurry::HashSet; let set: HashSet<i32> = HashSet::new();
pub fn with_capacity(capacity: usize) -> Self
[src]
Creates an empty HashSet
with the specified capacity.
The hash map will be able to hold at least capacity
elements without
reallocating. If capacity
is 0, the hash map will not allocate.
Examples
use flurry::HashSet; let map: HashSet<&str, _> = HashSet::with_capacity(10);
Notes
There is no guarantee that the HashSet will not resize if capacity
elements are inserted. The set will resize based on key collision, so
bad key distribution may cause a resize before capacity
is reached.
For more information see the resizing behavior
of HashMap.
impl<T, S> HashSet<T, S>
[src]
pub fn with_hasher(hash_builder: S) -> Self
[src]
Creates an empty set which will use hash_builder
to hash values.
The created set has the default initial capacity.
Warning: hash_builder
is normally randomly generated, and is designed to
allow the set 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 flurry::{HashSet, DefaultHashBuilder}; let set = HashSet::with_hasher(DefaultHashBuilder::default()); let guard = set.guard(); set.insert(1, &guard);
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
[src]
Creates an empty set with the specified capacity
, using hash_builder
to hash the
values.
The set will be sized to accommodate capacity
elements with a low chance of reallocating
(assuming uniformly distributed hashes). If capacity
is 0, the call will not allocate,
and is equivalent to HashSet::new
.
Warning: hash_builder
is normally randomly generated, and is designed to allow the set
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 flurry::HashSet; use std::collections::hash_map::RandomState; let s = RandomState::new(); let set = HashSet::with_capacity_and_hasher(10, s); let guard = set.guard(); set.insert(1, &guard);
pub fn guard(&self) -> Guard
[src]
Pin a Guard
for use with this set.
Keep in mind that for as long as you hold onto this Guard
, you are preventing the
collection of garbage generated by the set.
pub fn len(&self) -> usize
[src]
Returns the number of elements in the set.
Examples
use flurry::HashSet; let set = HashSet::new(); let guard = set.guard(); set.insert(1, &guard); set.insert(2, &guard); assert_eq!(set.len(), 2);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the set is empty. Otherwise returns false
.
Examples
use flurry::HashSet; let set = HashSet::new(); assert!(set.is_empty()); set.insert("a", &set.guard()); assert!(!set.is_empty());
pub fn iter<'g>(&'g self, guard: &'g Guard) -> Keys<'g, T, ()>
[src]
An iterator visiting all elements in arbitrary order.
The iterator element type is &'g T
.
See HashMap::keys
for details.
Examples
use flurry::HashSet; let set = HashSet::new(); let guard = set.guard(); set.insert(1, &guard); set.insert(2, &guard); for x in set.iter(&guard) { println!("{}", x); }
impl<T, S> HashSet<T, S> where
T: Hash + Ord,
S: BuildHasher,
[src]
T: Hash + Ord,
S: BuildHasher,
pub fn contains<'g, Q: ?Sized>(&self, value: &Q, guard: &'g Guard) -> bool where
T: Borrow<Q>,
Q: Hash + Ord,
[src]
T: Borrow<Q>,
Q: Hash + Ord,
Returns true
if the given value is an element of this set.
The value may be any borrowed form of the set's value type, but
Hash
and Ord
on the borrowed form must match those for
the value type.
Examples
use flurry::HashSet; let set = HashSet::new(); let guard = set.guard(); set.insert(2, &guard); assert!(set.contains(&2, &guard)); assert!(!set.contains(&1, &guard));
pub fn get<'g, Q: ?Sized>(
&'g self,
value: &Q,
guard: &'g Guard
) -> Option<&'g T> where
T: Borrow<Q>,
Q: Hash + Ord,
[src]
&'g self,
value: &Q,
guard: &'g Guard
) -> Option<&'g T> where
T: Borrow<Q>,
Q: Hash + Ord,
Returns a reference to the element in the set, if any, that is equal to the given value.
The value may be any borrowed form of the set's value type, but
Hash
and Ord
on the borrowed form must match those for
the value type.
Examples
use flurry::HashSet; let set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); let guard = set.guard(); assert_eq!(set.get(&2, &guard), Some(&2)); assert_eq!(set.get(&4, &guard), None);
pub fn is_disjoint(
&self,
other: &HashSet<T, S>,
our_guard: &Guard,
their_guard: &Guard
) -> bool
[src]
&self,
other: &HashSet<T, S>,
our_guard: &Guard,
their_guard: &Guard
) -> bool
Returns true
if self
has no elements in common with other
.
This is equivalent to checking for an empty intersection.
Examples
use std::iter::FromIterator; use flurry::HashSet; let a = HashSet::from_iter(&[1, 2, 3]); let b = HashSet::new(); assert!(a.pin().is_disjoint(&b.pin())); b.pin().insert(4); assert!(a.pin().is_disjoint(&b.pin())); b.pin().insert(1); assert!(!a.pin().is_disjoint(&b.pin()));
pub fn is_subset(
&self,
other: &HashSet<T, S>,
our_guard: &Guard,
their_guard: &Guard
) -> bool
[src]
&self,
other: &HashSet<T, S>,
our_guard: &Guard,
their_guard: &Guard
) -> bool
Returns true
if the set is a subset of another, i.e., other
contains at least all the values in self
.
Examples
use std::iter::FromIterator; use flurry::HashSet; let sup = HashSet::from_iter(&[1, 2, 3]); let set = HashSet::new(); assert!(set.pin().is_subset(&sup.pin())); set.pin().insert(2); assert!(set.pin().is_subset(&sup.pin())); set.pin().insert(4); assert!(!set.pin().is_subset(&sup.pin()));
pub fn is_superset(
&self,
other: &HashSet<T, S>,
our_guard: &Guard,
their_guard: &Guard
) -> bool
[src]
&self,
other: &HashSet<T, S>,
our_guard: &Guard,
their_guard: &Guard
) -> bool
Returns true
if the set is a superset of another, i.e., self
contains at least all the values in other
.
Examples
use std::iter::FromIterator; use flurry::HashSet; let sub = HashSet::from_iter(&[1, 2]); let set = HashSet::new(); assert!(!set.pin().is_superset(&sub.pin())); set.pin().insert(0); set.pin().insert(1); assert!(!set.pin().is_superset(&sub.pin())); set.pin().insert(2); assert!(set.pin().is_superset(&sub.pin()));
impl<T, S> HashSet<T, S> where
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
[src]
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
pub fn insert(&self, value: T, guard: &Guard) -> bool
[src]
Adds a value to the set.
If the set did not have this value present, true
is returned.
If the set did have this value present, false
is returned.
Examples
use flurry::HashSet; let set = HashSet::new(); let guard = set.guard(); assert_eq!(set.insert(2, &guard), true); assert_eq!(set.insert(2, &guard), false); assert!(set.contains(&2, &guard));
pub fn remove<Q: ?Sized>(&self, value: &Q, guard: &Guard) -> bool where
T: Borrow<Q>,
Q: Hash + Ord,
[src]
T: Borrow<Q>,
Q: Hash + Ord,
Removes a value from the set.
If the set did not have this value present, false
is returned.
If the set did have this value present, true
is returned.
The value may be any borrowed form of the set's value type, but
Hash
and Ord
on the borrowed form must match those for
the value type.
Examples
use flurry::HashSet; let set = HashSet::new(); let guard = set.guard(); set.insert(2, &guard); assert_eq!(set.remove(&2, &guard), true); assert!(!set.contains(&2, &guard)); assert_eq!(set.remove(&2, &guard), false);
pub fn take<'g, Q: ?Sized>(
&'g self,
value: &Q,
guard: &'g Guard
) -> Option<&'g T> where
T: Borrow<Q>,
Q: Hash + Ord,
[src]
&'g self,
value: &Q,
guard: &'g Guard
) -> Option<&'g T> where
T: Borrow<Q>,
Q: Hash + Ord,
Removes and returns the value in the set, if any, that is equal to the given one.
The value may be any borrowed form of the set's value type, but
Hash
and Ord
on the borrowed form must match those for
the value type.
Examples
use flurry::HashSet; let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); let guard = set.guard(); assert_eq!(set.take(&2, &guard), Some(&2)); assert_eq!(set.take(&2, &guard), None);
pub fn retain<F>(&self, f: F, guard: &Guard) where
F: FnMut(&T) -> bool,
[src]
F: FnMut(&T) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all elements e
such that f(&e)
returns false
.
Examples
use flurry::HashSet; let set = HashSet::new(); for i in 0..8 { set.pin().insert(i); } set.pin().retain(|&e| e % 2 == 0); assert_eq!(set.pin().len(), 4);
impl<T, S> HashSet<T, S> where
T: Clone + Ord,
[src]
T: Clone + Ord,
pub fn clear(&self, guard: &Guard)
[src]
Clears the set, removing all elements.
Examples
use flurry::HashSet; let set = HashSet::new(); set.pin().insert("a"); set.pin().clear(); assert!(set.pin().is_empty());
pub fn reserve(&self, additional: usize, guard: &Guard)
[src]
Tries to reserve capacity for at least additional
more elements to
be inserted in the HashSet
.
The collection may reserve more space to avoid frequent reallocations.
impl<T, S> HashSet<T, S>
[src]
pub fn pin(&self) -> HashSetRef<T, S>
[src]
Get a reference to this set with the current thread pinned.
Keep in mind that for as long as you hold onto this, you are preventing the collection of garbage generated by the set.
pub fn with_guard<'g>(&'g self, guard: &'g Guard) -> HashSetRef<'g, T, S>
[src]
Get a reference to this set with the given guard.
Trait Implementations
impl<T, S> Clone for HashSet<T, S> where
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher + Clone,
[src]
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher + Clone,
impl<T, S> Debug for HashSet<T, S> where
T: Debug,
[src]
T: Debug,
impl<T, S> Default for HashSet<T, S> where
S: Default,
[src]
S: Default,
impl<T, S> Eq for HashSet<T, S> where
T: Ord + Hash,
S: BuildHasher,
[src]
T: Ord + Hash,
S: BuildHasher,
impl<'a, '_, T, S> Extend<&'a T> for &'_ HashSet<T, S> where
T: 'static + Sync + Send + Copy + Hash + Ord,
S: BuildHasher,
[src]
T: 'static + Sync + Send + Copy + Hash + Ord,
S: BuildHasher,
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
[src]
impl<'_, T, S> Extend<T> for &'_ HashSet<T, S> where
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
[src]
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher,
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
impl<'a, T, S> FromIterator<&'a T> for HashSet<T, S> where
T: 'static + Sync + Send + Copy + Hash + Ord,
S: BuildHasher + Default,
[src]
T: 'static + Sync + Send + Copy + Hash + Ord,
S: BuildHasher + Default,
fn from_iter<I: IntoIterator<Item = &'a T>>(iter: I) -> Self
[src]
impl<T, S> FromIterator<T> for HashSet<T, S> where
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher + Default,
[src]
T: 'static + Sync + Send + Clone + Hash + Ord,
S: BuildHasher + Default,
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
impl<T, S> PartialEq<HashSet<T, S>> for HashSet<T, S> where
T: Ord + Hash,
S: BuildHasher,
[src]
T: Ord + Hash,
S: BuildHasher,
impl<'_, T, S> PartialEq<HashSet<T, S>> for HashSetRef<'_, T, S> where
T: Hash + Ord,
S: BuildHasher,
[src]
T: Hash + Ord,
S: BuildHasher,
fn eq(&self, other: &HashSet<T, S>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'_, T, S> PartialEq<HashSetRef<'_, T, S>> for HashSet<T, S> where
T: Hash + Ord,
S: BuildHasher,
[src]
T: Hash + Ord,
S: BuildHasher,
Auto Trait Implementations
impl<T, S = RandomState> !RefUnwindSafe for HashSet<T, S>
impl<T, S> Send for HashSet<T, S> where
S: Send,
T: Send + Sync,
S: Send,
T: Send + Sync,
impl<T, S> Sync for HashSet<T, S> where
S: Sync,
T: Send + Sync,
S: Sync,
T: Send + Sync,
impl<T, S> Unpin for HashSet<T, S> where
S: Unpin,
S: Unpin,
impl<T, S = RandomState> !UnwindSafe for HashSet<T, S>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,