[][src]Struct contrie::set::ConSet

pub struct ConSet<T, S = RandomState> where
    T: Clone + Hash + Eq + 'static, 
{ /* fields omitted */ }

A concurrent lock-free set.

Note that due to the limitations described in the crate level docs, values returned by looking up (or misplacing or removing) are always copied using the Clone trait. Therefore, the set is more suitable for types that are cheap to copy (eg. u64 or IpAddr).

If you intend to store types that are more expensive to make copies of or are not Clone, you can wrap them in an Arc (eg. Arc<str>).

use contrie::ConSet;
use crossbeam_utils::thread;

let set = ConSet::new();

thread::scope(|s| {
    s.spawn(|_| {
        set.insert("hello");
    });
    s.spawn(|_| {
        set.insert("world");
    });
}).unwrap();

assert_eq!(Some("hello"), set.get("hello"));
assert_eq!(Some("world"), set.get("world"));
assert_eq!(None, set.get("universe"));
set.remove("world");
assert_eq!(None, set.get("world"));
use contrie::set::{ConSet};
let set: ConSet<usize> = ConSet::new();

set.insert(0);
set.insert(1);

assert!(set.contains(&1));

set.remove(&1);
assert!(!set.contains(&1));

set.remove(&0);
assert!(set.is_empty());

Methods

impl<T> ConSet<T, RandomState> where
    T: Clone + Hash + Eq + 'static, 
[src]

pub fn new() -> Self[src]

Creates a new empty set.

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

pub fn with_hasher(hasher: S) -> Self[src]

Creates a new empty set with the given hasher.

pub fn insert(&self, value: T) -> Option<T>[src]

Inserts a new value into the set.

It returns the previous value, if any was present.

pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<T> where
    Q: Eq + Hash,
    T: Borrow<Q>, 
[src]

Looks up a value in the set.

This creates a copy of the original value.

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

Checks if a value identified by the given key is present in the set.

Note that by the time you can act on it, the presence of the value can change (eg. other thread can add or remove it in the meantime).

pub fn remove<Q: ?Sized>(&self, key: &Q) -> Option<T> where
    Q: Eq + Hash,
    T: Borrow<Q>, 
[src]

Removes an element identified by the given key, returning it.

pub fn is_empty(&self) -> bool[src]

Checks if the set is currently empty.

Note that due to being concurrent, the use-case of this method is mostly for debugging purposes, because the state can change between reading the value and acting on it.

impl<T, S> ConSet<T, S> where
    T: Clone + Hash + Eq + 'static, 
[src]

Important traits for Iter<'a, T, S>
pub fn iter(&self) -> Iter<T, S>[src]

Returns an iterator through the elements of the set.

Trait Implementations

impl<T> Default for ConSet<T, RandomState> where
    T: Clone + Hash + Eq + 'static, 
[src]

impl<'a, T, S> IntoIterator for &'a ConSet<T, S> where
    T: Clone + Hash + Eq + 'static, 
[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T, S>

Which kind of iterator are we turning this into?

impl<'a, T, S> Extend<T> for &'a ConSet<T, S> where
    T: Clone + Hash + Eq + 'static,
    S: BuildHasher
[src]

impl<T, S> Extend<T> for ConSet<T, S> where
    T: Clone + Hash + Eq + 'static,
    S: BuildHasher
[src]

impl<T, S> Debug for ConSet<T, S> where
    T: Debug + Clone + Hash + Eq + 'static, 
[src]

impl<T> FromIterator<T> for ConSet<T> where
    T: Clone + Hash + Eq + 'static, 
[src]

impl<T> FromParallelIterator<T> for ConSet<T> where
    T: Clone + Hash + Eq + Send + Sync
[src]

impl<'a, T, S> ParallelExtend<T> for &'a ConSet<T, S> where
    T: Clone + Hash + Eq + Send + Sync,
    S: BuildHasher + Sync
[src]

impl<T, S> ParallelExtend<T> for ConSet<T, S> where
    T: Clone + Hash + Eq + Send + Sync,
    S: BuildHasher + Sync
[src]

Auto Trait Implementations

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

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

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

impl<T, S> RefUnwindSafe for ConSet<T, S> where
    S: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, S> UnwindSafe for ConSet<T, S> where
    S: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

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

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

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.

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

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

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