pub struct ConSet<T, S = RandomState>{ /* private fields */ }Expand description
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());Implementations§
Source§impl<T> ConSet<T, RandomState>
impl<T> ConSet<T, RandomState>
Source§impl<T, S> ConSet<T, S>
impl<T, S> ConSet<T, S>
Sourcepub fn with_hasher(hasher: S) -> Self
pub fn with_hasher(hasher: S) -> Self
Creates a new empty set with the given hasher.
Sourcepub fn insert(&self, value: T) -> Option<T>
pub fn insert(&self, value: T) -> Option<T>
Inserts a new value into the set.
It returns the previous value, if any was present.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<T>
pub fn get<Q>(&self, key: &Q) -> Option<T>
Looks up a value in the set.
This creates a copy of the original value.
Sourcepub fn contains<Q>(&self, key: &Q) -> bool
pub fn contains<Q>(&self, key: &Q) -> bool
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).
Trait Implementations§
Source§impl<T> Default for ConSet<T, RandomState>
impl<T> Default for ConSet<T, RandomState>
Source§impl<'a, T, S> Extend<T> for &'a ConSet<T, S>
impl<'a, T, S> Extend<T> for &'a ConSet<T, S>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T, S> Extend<T> for ConSet<T, S>
impl<T, S> Extend<T> for ConSet<T, S>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> FromIterator<T> for ConSet<T>
impl<T> FromIterator<T> for ConSet<T>
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Source§impl<T> FromParallelIterator<T> for ConSet<T>
impl<T> FromParallelIterator<T> for ConSet<T>
Source§fn from_par_iter<I>(iter: I) -> Selfwhere
I: IntoParallelIterator<Item = T>,
fn from_par_iter<I>(iter: I) -> Selfwhere
I: IntoParallelIterator<Item = T>,
par_iter. Read moreSource§impl<'a, T, S> IntoIterator for &'a ConSet<T, S>
impl<'a, T, S> IntoIterator for &'a ConSet<T, S>
Source§impl<'a, T, S> ParallelExtend<T> for &'a ConSet<T, S>
impl<'a, T, S> ParallelExtend<T> for &'a ConSet<T, S>
Source§fn par_extend<I>(&mut self, par_iter: I)where
I: IntoParallelIterator<Item = T>,
fn par_extend<I>(&mut self, par_iter: I)where
I: IntoParallelIterator<Item = T>,
par_iter. Read moreSource§impl<T, S> ParallelExtend<T> for ConSet<T, S>
impl<T, S> ParallelExtend<T> for ConSet<T, S>
Source§fn par_extend<I>(&mut self, par_iter: I)where
I: IntoParallelIterator<Item = T>,
fn par_extend<I>(&mut self, par_iter: I)where
I: IntoParallelIterator<Item = T>,
par_iter. Read moreAuto Trait Implementations§
impl<T, S = RandomState> !Freeze for ConSet<T, S>
impl<T, S> RefUnwindSafe for ConSet<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for ConSet<T, S>
impl<T, S> Sync for ConSet<T, S>
impl<T, S> Unpin for ConSet<T, S>
impl<T, S> UnwindSafe for ConSet<T, S>where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more