[−][src]Struct contrie::set::ConSet
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]
T: Clone + Hash + Eq + 'static,
impl<T, S> ConSet<T, S> where
T: Clone + Hash + Eq + 'static,
S: BuildHasher,
[src]
T: Clone + Hash + Eq + 'static,
S: BuildHasher,
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]
Q: Eq + Hash,
T: Borrow<Q>,
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]
Q: Eq + Hash,
T: Borrow<Q>,
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]
Q: Eq + Hash,
T: Borrow<Q>,
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]
T: Clone + Hash + Eq + 'static,
ⓘ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]
T: Clone + Hash + Eq + 'static,
impl<'a, T, S> IntoIterator for &'a ConSet<T, S> where
T: Clone + Hash + Eq + 'static,
[src]
T: Clone + Hash + Eq + 'static,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T, S> Extend<T> for &'a ConSet<T, S> where
T: Clone + Hash + Eq + 'static,
S: BuildHasher,
[src]
T: Clone + Hash + Eq + 'static,
S: BuildHasher,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<T, S> Extend<T> for ConSet<T, S> where
T: Clone + Hash + Eq + 'static,
S: BuildHasher,
[src]
T: Clone + Hash + Eq + 'static,
S: BuildHasher,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<T, S> Debug for ConSet<T, S> where
T: Debug + Clone + Hash + Eq + 'static,
[src]
T: Debug + Clone + Hash + Eq + 'static,
impl<T> FromIterator<T> for ConSet<T> where
T: Clone + Hash + Eq + 'static,
[src]
T: Clone + Hash + Eq + 'static,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<T> FromParallelIterator<T> for ConSet<T> where
T: Clone + Hash + Eq + Send + Sync,
[src]
T: Clone + Hash + Eq + Send + Sync,
fn from_par_iter<I>(iter: I) -> Self where
I: IntoParallelIterator<Item = T>,
[src]
I: IntoParallelIterator<Item = T>,
impl<'a, T, S> ParallelExtend<T> for &'a ConSet<T, S> where
T: Clone + Hash + Eq + Send + Sync,
S: BuildHasher + Sync,
[src]
T: Clone + Hash + Eq + Send + Sync,
S: BuildHasher + Sync,
fn par_extend<I>(&mut self, par_iter: I) where
I: IntoParallelIterator<Item = T>,
[src]
I: IntoParallelIterator<Item = T>,
impl<T, S> ParallelExtend<T> for ConSet<T, S> where
T: Clone + Hash + Eq + Send + Sync,
S: BuildHasher + Sync,
[src]
T: Clone + Hash + Eq + Send + Sync,
S: BuildHasher + Sync,
fn par_extend<I>(&mut self, par_iter: I) where
I: IntoParallelIterator<Item = T>,
[src]
I: IntoParallelIterator<Item = T>,
Auto Trait Implementations
impl<T, S> Unpin for ConSet<T, S> where
S: Unpin,
T: Unpin,
S: Unpin,
T: Unpin,
impl<T, S> Sync for ConSet<T, S> where
S: Sync,
T: Sync,
S: Sync,
T: Sync,
impl<T, S> Send for ConSet<T, S> where
S: Send,
T: Send,
S: Send,
T: Send,
impl<T, S> RefUnwindSafe for ConSet<T, S> where
S: RefUnwindSafe,
T: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> UnwindSafe for ConSet<T, S> where
S: UnwindSafe,
T: UnwindSafe,
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]
U: From<T>,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,