[][src]Struct flurry::HashSet

pub struct HashSet<T, S = DefaultHashBuilder> { /* fields omitted */ }

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 entries 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());

Important traits for Keys<'g, K, V>
pub fn iter<'g>(&'g self, guard: &'g Guard) -> Keys<'g, T, ()>[src]

An iterator visiting all values in arbitrary order.

The iterator element type is (&'g K, &'g V).

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 + Eq,
    S: BuildHasher
[src]

pub fn contains<'g, Q: ?Sized>(&self, value: &Q, guard: &'g Guard) -> bool where
    T: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns true if the set contains the specified value.

The value may be any borrowed form of the set's value type, but Hash and Eq 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 + Eq
[src]

Returns a reference to the value 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 Eq 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);

impl<T, S> HashSet<T, S> where
    T: 'static + Sync + Send + Clone + Hash + Eq,
    S: BuildHasher
[src]

pub fn insert<'g>(&'g self, value: T, guard: &'g 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<'g, Q: ?Sized>(&'g self, value: &Q, guard: &'g Guard) -> bool where
    T: Borrow<Q>,
    Q: Hash + Eq
[src]

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 Eq 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 + Eq
[src]

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 Eq 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);

Trait Implementations

impl<T, S> Clone for HashSet<T, S> where
    T: 'static + Sync + Send + Clone + Hash + Eq,
    S: BuildHasher + Clone
[src]

impl<T, S> Debug for HashSet<T, S> where
    T: Debug
[src]

impl<T, S> Default for HashSet<T, S> where
    S: Default
[src]

impl<T, S> Eq for HashSet<T, S> where
    T: Eq + Hash,
    S: BuildHasher
[src]

impl<'a, '_, T, S> Extend<&'a T> for &'_ HashSet<T, S> where
    T: 'static + Sync + Send + Copy + Hash + Eq,
    S: BuildHasher
[src]

impl<'_, T, S> Extend<T> for &'_ HashSet<T, S> where
    T: 'static + Sync + Send + Clone + Hash + Eq,
    S: BuildHasher
[src]

impl<'a, T, S> FromIterator<&'a T> for HashSet<T, S> where
    T: 'static + Sync + Send + Copy + Hash + Eq,
    S: BuildHasher + Default
[src]

impl<T, S> FromIterator<T> for HashSet<T, S> where
    T: 'static + Sync + Send + Clone + Hash + Eq,
    S: BuildHasher + Default
[src]

impl<T, S> PartialEq<HashSet<T, S>> for HashSet<T, S> where
    T: Eq + Hash,
    S: BuildHasher
[src]

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

impl<T, S> Sync for HashSet<T, S> where
    S: Sync,
    T: Send + Sync

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

impl<T, S = RandomState> !UnwindSafe for HashSet<T, S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.