pub struct CloneConMap<K, V, S = RandomState>{ /* private fields */ }Expand description
A concurrent map that clones its elements.
This flavour stores the data as (K, V) tuples; it clones
independently both the elements (to be intended as the key and the
value) of the tuple. The return values of its functions are clones
of the stored values. This makes this data structure suitable for
types cheap to clone.
Iteration returns cloned copies of its elements. The
FromIterator and Extend traits accept tuples as arguments.
Furthermore, the Extend is also implemented for shared
references (to allow extending the same map concurrently from
multiple threads).
§Examples
use contrie::CloneConMap;
use crossbeam_utils::thread;
let map = CloneConMap::new();
thread::scope(|s| {
s.spawn(|_| {
map.insert("hello", 1);
});
s.spawn(|_| {
map.insert("world", 2);
});
}).unwrap();
assert_eq!(1, map.get("hello").unwrap().1);
assert_eq!(2, map.get("world").unwrap().1);use contrie::clonemap::{CloneConMap};
let map_1: CloneConMap<usize, Vec<usize>> = CloneConMap::new();
map_1.insert(42, vec![1, 2, 3]);
map_1.insert(43, vec![1, 2, 3, 4]);
assert_eq!(3, map_1.get(&42).unwrap().1.len());
assert_eq!(4, map_1.get(&43).unwrap().1.len());
assert_eq!(None, map_1.get(&44));
let map_2 = CloneConMap::new();
map_2.insert(44, map_1.get(&43).unwrap().1);
assert_eq!(4, map_2.get(&44).unwrap().1.len());Implementations§
Source§impl<K, V> CloneConMap<K, V>
impl<K, V> CloneConMap<K, V>
Source§impl<K, V, S> CloneConMap<K, V, S>
impl<K, V, S> CloneConMap<K, V, S>
Sourcepub fn insert(&self, key: K, value: V) -> Option<(K, V)>
pub fn insert(&self, key: K, value: V) -> Option<(K, V)>
Inserts a new element as a tuple (key, value).
Any previous element with the same key is replaced and returned.
Sourcepub fn get_or_insert(&self, key: K, value: V) -> ExistingOrNew<(K, V)>
pub fn get_or_insert(&self, key: K, value: V) -> ExistingOrNew<(K, V)>
Looks up or inserts an element as a tuple (key, value).
It looks up an element. If it isn’t present, the provided one is inserted instead. Either way, an element is returned.
Sourcepub fn get_or_insert_with<F>(&self, key: K, create: F) -> ExistingOrNew<(K, V)>where
F: FnOnce() -> V,
pub fn get_or_insert_with<F>(&self, key: K, create: F) -> ExistingOrNew<(K, V)>where
F: FnOnce() -> V,
Looks up or inserts a newly created element.
It looks up an element. If it isn’t present, the provided closure is used to create a new one insert it. Either way, an element is returned.
§Quirks
Due to races in case of concurrent accesses, the closure may be called even if the value is not subsequently inserted and an existing element is returned. This should be relatively rare (another thread must insert the new element between this method observes an empty slot and manages to insert the new element).
Sourcepub fn get_or_insert_default(&self, key: K) -> ExistingOrNew<(K, V)>where
V: Default,
pub fn get_or_insert_default(&self, key: K) -> ExistingOrNew<(K, V)>where
V: Default,
Looks up or inserts a default value of an element.
This is like get_or_insert_with, but a default value is used instead of manually providing a closure.
Source§impl<K, V, S> CloneConMap<K, V, S>
impl<K, V, S> CloneConMap<K, V, S>
Trait Implementations§
Source§impl<K, V, S> Clone for CloneConMap<K, V, S>
impl<K, V, S> Clone for CloneConMap<K, V, S>
Source§impl<K, V, S> Debug for CloneConMap<K, V, S>
impl<K, V, S> Debug for CloneConMap<K, V, S>
Source§impl<K, V> Default for CloneConMap<K, V>
impl<K, V> Default for CloneConMap<K, V>
Source§impl<'a, K, V, S> Extend<(K, V)> for &'a CloneConMap<K, V, S>
impl<'a, K, V, S> Extend<(K, V)> for &'a CloneConMap<K, V, S>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
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<K, V, S> Extend<(K, V)> for CloneConMap<K, V, S>
impl<K, V, S> Extend<(K, V)> for CloneConMap<K, V, S>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
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<K, V> FromIterator<(K, V)> for CloneConMap<K, V>
impl<K, V> FromIterator<(K, V)> for CloneConMap<K, V>
Source§impl<K, V> FromParallelIterator<(K, V)> for CloneConMap<K, V>
impl<K, V> FromParallelIterator<(K, V)> for CloneConMap<K, V>
Source§fn from_par_iter<T>(par_iter: T) -> Selfwhere
T: IntoParallelIterator<Item = (K, V)>,
fn from_par_iter<T>(par_iter: T) -> Selfwhere
T: IntoParallelIterator<Item = (K, V)>,
par_iter. Read moreSource§impl<'a, K, V, S> IntoIterator for &'a CloneConMap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a CloneConMap<K, V, S>
Source§impl<'a, K, V, S> ParallelExtend<(K, V)> for &'a CloneConMap<K, V, S>
impl<'a, K, V, S> ParallelExtend<(K, V)> for &'a CloneConMap<K, V, S>
Source§fn par_extend<T>(&mut self, par_iter: T)where
T: IntoParallelIterator<Item = (K, V)>,
fn par_extend<T>(&mut self, par_iter: T)where
T: IntoParallelIterator<Item = (K, V)>,
par_iter. Read moreSource§impl<K, V, S> ParallelExtend<(K, V)> for CloneConMap<K, V, S>
impl<K, V, S> ParallelExtend<(K, V)> for CloneConMap<K, V, S>
Source§fn par_extend<T>(&mut self, par_iter: T)where
T: IntoParallelIterator<Item = (K, V)>,
fn par_extend<T>(&mut self, par_iter: T)where
T: IntoParallelIterator<Item = (K, V)>,
par_iter. Read moreAuto Trait Implementations§
impl<K, V, S = RandomState> !Freeze for CloneConMap<K, V, S>
impl<K, V, S> RefUnwindSafe for CloneConMap<K, V, S>
impl<K, V, S> Send for CloneConMap<K, V, S>
impl<K, V, S> Sync for CloneConMap<K, V, S>
impl<K, V, S> Unpin for CloneConMap<K, V, S>
impl<K, V, S> UnwindSafe for CloneConMap<K, V, S>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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