Struct dashmap::DashMap [−][src]
DashMap is an implementation of a concurrent associative array/hashmap in Rust.
DashMap tries to implement an easy to use API similar to std::collections::HashMap
with some slight changes to handle concurrency.
DashMap tries to be very simple to use and to be a direct replacement for RwLock<HashMap<K, V, S>>
.
To accomplish these all methods take &self
instead modifying methods taking &mut self
.
This allows you to put a DashMap in an Arc<T>
and share it between threads while being able to modify it.
Implementations
impl<'a, K: 'a + Eq + Hash, V: 'a> DashMap<K, V, RandomState>
[src]
pub fn new() -> Self
[src]
Creates a new DashMap with a capacity of 0.
Examples
use dashmap::DashMap; let reviews = DashMap::new(); reviews.insert("Veloren", "What a fantastic game!");
pub fn with_capacity(capacity: usize) -> Self
[src]
Creates a new DashMap with a specified starting capacity.
Examples
use dashmap::DashMap; let mappings = DashMap::with_capacity(2); mappings.insert(2, 4); mappings.insert(8, 16);
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap<K, V, S>
[src]
pub fn into_read_only(self) -> ReadOnlyView<K, V, S>
[src]
Wraps this DashMap
into a read-only view. This view allows to obtain raw references to the stored values.
pub fn with_hasher(hasher: S) -> Self
[src]
Creates a new DashMap with a capacity of 0 and the provided hasher.
Examples
use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let reviews = DashMap::with_hasher(s); reviews.insert("Veloren", "What a fantastic game!");
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
[src]
Creates a new DashMap with a specified starting capacity and hasher.
Examples
use dashmap::DashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mappings = DashMap::with_capacity_and_hasher(2, s); mappings.insert(2, 4); mappings.insert(8, 16);
pub fn hash_usize<T: Hash>(&self, item: &T) -> usize
[src]
Hash a given item to produce a usize. Uses the provided or default HashBuilder.
pub fn hasher(&self) -> &S
[src]
Returns a reference to the map’s BuildHasher
.
Examples
use dashmap::DashMap; use ahash::RandomState; let hasher = RandomState::new(); let map: DashMap<i32, i32> = DashMap::new(); let hasher: &RandomState = map.hasher();
pub fn insert(&self, key: K, value: V) -> Option<V>
[src]
Inserts a key and a value into the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let map = DashMap::new(); map.insert("I am the key!", "And I am the value!");
pub fn remove<Q: ?Sized>(&self, key: &Q) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Removes an entry from the map, returning the key and value if they existed in the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let soccer_team = DashMap::new(); soccer_team.insert("Jack", "Goalie"); assert_eq!(soccer_team.remove("Jack").unwrap().1, "Goalie");
pub fn remove_if<Q: ?Sized>(
&self,
key: &Q,
f: impl FnOnce(&K, &V) -> bool
) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
&self,
key: &Q,
f: impl FnOnce(&K, &V) -> bool
) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq,
Removes an entry from the map, returning the key and value if the entry existed and the provided conditional function returned true.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
use dashmap::DashMap; let soccer_team = DashMap::new(); soccer_team.insert("Sam", "Forward"); soccer_team.remove_if("Sam", |_, position| position == &"Goalie"); assert!(soccer_team.contains_key("Sam"));
use dashmap::DashMap; let soccer_team = DashMap::new(); soccer_team.insert("Sam", "Forward"); soccer_team.remove_if("Sam", |_, position| position == &"Forward"); assert!(!soccer_team.contains_key("Sam"));
pub fn iter(&'a self) -> Iter<'a, K, V, S, DashMap<K, V, S>>ⓘ
[src]
Creates an iterator over a DashMap yielding immutable references.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
Examples
use dashmap::DashMap; let words = DashMap::new(); words.insert("hello", "world"); assert_eq!(words.iter().count(), 1);
pub fn iter_mut(&'a self) -> IterMut<'a, K, V, S, DashMap<K, V, S>>ⓘNotable traits for IterMut<'a, K, V, S, M>
impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iterator for IterMut<'a, K, V, S, M> type Item = RefMutMulti<'a, K, V, S>;
[src]
Notable traits for IterMut<'a, K, V, S, M>
impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iterator for IterMut<'a, K, V, S, M> type Item = RefMutMulti<'a, K, V, S>;
Iterator over a DashMap yielding mutable references.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let map = DashMap::new(); map.insert("Johnny", 21); map.iter_mut().for_each(|mut r| *r += 1); assert_eq!(*map.get("Johnny").unwrap(), 22);
pub fn get<Q: ?Sized>(&'a self, key: &Q) -> Option<Ref<'a, K, V, S>> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Get a immutable reference to an entry in the map
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
Examples
use dashmap::DashMap; let youtubers = DashMap::new(); youtubers.insert("Bosnian Bill", 457000); assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), 457000);
pub fn get_mut<Q: ?Sized>(&'a self, key: &Q) -> Option<RefMut<'a, K, V, S>> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Get a mutable reference to an entry in the map
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let class = DashMap::new(); class.insert("Albin", 15); *class.get_mut("Albin").unwrap() -= 1; assert_eq!(*class.get("Albin").unwrap(), 14);
pub fn shrink_to_fit(&self)
[src]
Remove excess capacity to reduce memory usage.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
pub fn retain(&self, f: impl FnMut(&K, &mut V) -> bool)
[src]
Retain elements that whose predicates return true and discard elements whose predicates return false.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let people = DashMap::new(); people.insert("Albin", 15); people.insert("Jones", 22); people.insert("Charlie", 27); people.retain(|_, v| *v > 20); assert_eq!(people.len(), 2);
pub fn len(&self) -> usize
[src]
Fetches the total number of key-value pairs stored in the map.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
Examples
use dashmap::DashMap; let people = DashMap::new(); people.insert("Albin", 15); people.insert("Jones", 22); people.insert("Charlie", 27); assert_eq!(people.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Checks if the map is empty or not.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
Examples
use dashmap::DashMap; let map = DashMap::<(), ()>::new(); assert!(map.is_empty());
pub fn clear(&self)
[src]
Removes all key-value pairs in the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let stats = DashMap::new(); stats.insert("Goals", 4); assert!(!stats.is_empty()); stats.clear(); assert!(stats.is_empty());
pub fn capacity(&self) -> usize
[src]
Returns how many key-value pairs the map can store without reallocating.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
pub fn alter<Q: ?Sized>(&self, key: &Q, f: impl FnOnce(&K, V) -> V) where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Modify a specific value according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let stats = DashMap::new(); stats.insert("Goals", 4); stats.alter("Goals", |_, v| v * 2); assert_eq!(*stats.get("Goals").unwrap(), 8);
Panics
If the given closure panics, then alter_all
will abort the process
pub fn alter_all(&self, f: impl FnMut(&K, V) -> V)
[src]
Modify every value in the map according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Examples
use dashmap::DashMap; let stats = DashMap::new(); stats.insert("Wins", 4); stats.insert("Losses", 2); stats.alter_all(|_, v| v + 1); assert_eq!(*stats.get("Wins").unwrap(), 5); assert_eq!(*stats.get("Losses").unwrap(), 3);
Panics
If the given closure panics, then alter_all
will abort the process
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Checks if the map contains a specific key.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
Examples
use dashmap::DashMap; let team_sizes = DashMap::new(); team_sizes.insert("Dakota Cherries", 23); assert!(team_sizes.contains_key("Dakota Cherries"));
pub fn entry(&'a self, key: K) -> Entry<'a, K, V, S>
[src]
Advanced entry API that tries to mimic std::collections::HashMap
.
See the documentation on dashmap::mapref::entry
for more details.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
Trait Implementations
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone, Q: ?Sized> BitAnd<&'_ Q> for &'a DashMap<K, V, S> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
type Output = bool
The resulting type after applying the &
operator.
fn bitand(self, key: &Q) -> Self::Output
[src]
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone, Q: ?Sized> BitOr<&'_ Q> for &'a DashMap<K, V, S> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
type Output = RefMut<'a, K, V, S>
The resulting type after applying the |
operator.
fn bitor(self, key: &Q) -> Self::Output
[src]
impl<K: Eq + Hash + Clone, V: Clone, S: Clone> Clone for DashMap<K, V, S>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K: Eq + Hash + Debug, V: Debug, S: BuildHasher + Clone> Debug for DashMap<K, V, S>
[src]
impl<K, V, S> Default for DashMap<K, V, S> where
K: Eq + Hash,
S: Default + BuildHasher + Clone,
[src]
K: Eq + Hash,
S: Default + BuildHasher + Clone,
impl<K: Eq + Hash, V, S: BuildHasher + Clone> Extend<(K, V)> for DashMap<K, V, S>
[src]
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, intoiter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<K: Eq + Hash, V> FromIterator<(K, V)> for DashMap<K, V, RandomState>
[src]
fn from_iter<I: IntoIterator<Item = (K, V)>>(intoiter: I) -> Self
[src]
impl<'a, K: Eq + Hash, V, S: BuildHasher + Clone> IntoIterator for DashMap<K, V, S>
[src]
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = OwningIter<K, V, S>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K: Eq + Hash, V, S: BuildHasher + Clone> IntoIterator for &'a DashMap<K, V, S>
[src]
type Item = RefMulti<'a, K, V, S>
The type of the elements being iterated over.
type IntoIter = Iter<'a, K, V, S, DashMap<K, V, S>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + BuildHasher + Clone> Map<'a, K, V, S> for DashMap<K, V, S>
[src]
fn _shard_count(&self) -> usize
[src]
unsafe fn _get_read_shard(
&'a self,
i: usize
) -> &'a HashMap<K, SharedValue<V>, S>
[src]
&'a self,
i: usize
) -> &'a HashMap<K, SharedValue<V>, S>
unsafe fn _yield_read_shard(
&'a self,
i: usize
) -> RwLockReadGuard<'a, HashMap<K, SharedValue<V>, S>>
[src]
&'a self,
i: usize
) -> RwLockReadGuard<'a, HashMap<K, SharedValue<V>, S>>
unsafe fn _yield_write_shard(
&'a self,
i: usize
) -> RwLockWriteGuard<'a, HashMap<K, SharedValue<V>, S>>
[src]
&'a self,
i: usize
) -> RwLockWriteGuard<'a, HashMap<K, SharedValue<V>, S>>
fn _insert(&self, key: K, value: V) -> Option<V>
[src]
fn _remove<Q: ?Sized>(&self, key: &Q) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
fn _remove_if<Q: ?Sized>(
&self,
key: &Q,
f: impl FnOnce(&K, &V) -> bool
) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
&self,
key: &Q,
f: impl FnOnce(&K, &V) -> bool
) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Hash + Eq,
fn _iter(&'a self) -> Iter<'a, K, V, S, DashMap<K, V, S>>ⓘ
[src]
fn _iter_mut(&'a self) -> IterMut<'a, K, V, S, DashMap<K, V, S>>ⓘNotable traits for IterMut<'a, K, V, S, M>
impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iterator for IterMut<'a, K, V, S, M> type Item = RefMutMulti<'a, K, V, S>;
[src]
Notable traits for IterMut<'a, K, V, S, M>
impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iterator for IterMut<'a, K, V, S, M> type Item = RefMutMulti<'a, K, V, S>;
fn _get<Q: ?Sized>(&'a self, key: &Q) -> Option<Ref<'a, K, V, S>> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
fn _get_mut<Q: ?Sized>(&'a self, key: &Q) -> Option<RefMut<'a, K, V, S>> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
fn _shrink_to_fit(&self)
[src]
fn _retain(&self, f: impl FnMut(&K, &mut V) -> bool)
[src]
fn _len(&self) -> usize
[src]
fn _capacity(&self) -> usize
[src]
fn _alter<Q: ?Sized>(&self, key: &Q, f: impl FnOnce(&K, V) -> V) where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
fn _alter_all(&self, f: impl FnMut(&K, V) -> V)
[src]
fn _entry(&'a self, key: K) -> Entry<'a, K, V, S>
[src]
fn _hasher(&self) -> S
[src]
fn _clear(&self)
[src]
fn _contains_key<Q: ?Sized>(&'a self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
fn _is_empty(&self) -> bool
[src]
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> Shl<(K, V)> for &'a DashMap<K, V, S>
[src]
type Output = Option<V>
The resulting type after applying the <<
operator.
fn shl(self, pair: (K, V)) -> Self::Output
[src]
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone, Q: ?Sized> Shr<&'_ Q> for &'a DashMap<K, V, S> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
type Output = Ref<'a, K, V, S>
The resulting type after applying the >>
operator.
fn shr(self, key: &Q) -> Self::Output
[src]
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone, Q: ?Sized> Sub<&'_ Q> for &'a DashMap<K, V, S> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
Auto Trait Implementations
impl<K, V, S = RandomState> !RefUnwindSafe for DashMap<K, V, S>
impl<K, V, S> Send for DashMap<K, V, S> where
K: Send,
S: Send,
V: Send,
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for DashMap<K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<K, V, S> Unpin for DashMap<K, V, S> where
S: Unpin,
S: Unpin,
impl<K, V, S> UnwindSafe for DashMap<K, V, S> where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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>,