Expand description
this sync map used to many reader,writer less.space-for-time strategy
Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.
The Map type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.
The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.
The zero Map is empty and ready for use. A Map must not be copied after first use.
Implementations
sourceimpl<K: Eq + Hash + Clone + Ord, V> SyncMapImpl<K, V> where
K: Eq + Hash + Clone,
impl<K: Eq + Hash + Clone + Ord, V> SyncMapImpl<K, V> where
K: Eq + Hash + Clone,
pub fn new_arc() -> Arc<Self>
pub fn new() -> Self
pub fn with_capacity(_capacity: usize) -> Self
pub async fn insert(&self, k: K, v: V) -> Option<V> where
K: Clone + Ord,
pub fn insert_mut(&mut self, k: K, v: V) -> Option<V> where
K: Clone + Ord,
pub async fn remove(&self, k: &K) -> Option<V> where
K: Clone + Ord,
pub fn remove_mut(&mut self, k: &K) -> Option<V> where
K: Clone + Ord,
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub async fn clear(&self) where
K: Eq + Hash + Clone + Ord,
pub fn clear_mut(&mut self) where
K: Eq + Hash + Clone + Ord,
pub fn shrink_to_fit(&self)
pub fn shrink_to_fit_mut(&mut self)
pub fn from(map: HashMap<K, V>) -> Self where
K: Clone + Eq + Hash + Ord,
sourcepub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q> + Ord,
Q: Hash + Eq + Ord,
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q> + Ord,
Q: Hash + Eq + Ord,
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Since reading a map is unlocked, it is very fast
test bench_sync_hash_map_read … bench: 8 ns/iter (+/- 0)
Examples
use dark_std::sync::{SyncBtreeMap};
let mut map = SyncBtreeMap::new();
map.insert_mut(1, "a");
assert_eq!(*map.get(&1).unwrap(), "a");
assert_eq!(map.get(&2).is_none(), true);
pub async fn get_mut<Q: ?Sized>(&self, k: &Q) -> Option<SyncMapRefMut<'_, K, V>> where
K: Borrow<Q> + Ord,
Q: Hash + Eq + Ord,
pub fn iter(&self) -> MapIter<'_, K, V>
pub async fn iter_mut(&self) -> IterMut<'_, K, V>
pub fn into_iter(self) -> MapIntoIter<K, V>
pub async fn dirty_ref(&self) -> MutexGuard<'_, HashMap<K, V>>
Trait Implementations
sourceimpl<K: Eq + Hash + Clone + Ord, V> Debug for SyncMapImpl<K, V> where
K: Eq + Hash + Clone + Debug,
V: Debug,
impl<K: Eq + Hash + Clone + Ord, V> Debug for SyncMapImpl<K, V> where
K: Eq + Hash + Clone + Debug,
V: Debug,
sourceimpl<'de, K, V> Deserialize<'de> for SyncMapImpl<K, V> where
K: Eq + Hash + Clone + Deserialize<'de> + Ord,
V: Deserialize<'de>,
impl<'de, K, V> Deserialize<'de> for SyncMapImpl<K, V> where
K: Eq + Hash + Clone + Deserialize<'de> + Ord,
V: Deserialize<'de>,
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<K: Eq + Hash + Clone + Ord, V> From<HashMap<K, V, RandomState>> for SyncMapImpl<K, V>
impl<K: Eq + Hash + Clone + Ord, V> From<HashMap<K, V, RandomState>> for SyncMapImpl<K, V>
sourceimpl<'a, K: Eq + Hash + Clone + Ord, V> IntoIterator for &'a SyncMapImpl<K, V>
impl<'a, K: Eq + Hash + Clone + Ord, V> IntoIterator for &'a SyncMapImpl<K, V>
sourceimpl<K: Eq + Hash + Clone + Ord, V> IntoIterator for SyncMapImpl<K, V>
impl<K: Eq + Hash + Clone + Ord, V> IntoIterator for SyncMapImpl<K, V>
sourceimpl<K: Eq + Hash + Clone + Ord, V> Serialize for SyncMapImpl<K, V> where
K: Eq + Hash + Clone + Serialize,
V: Serialize,
impl<K: Eq + Hash + Clone + Ord, V> Serialize for SyncMapImpl<K, V> where
K: Eq + Hash + Clone + Serialize,
V: Serialize,
impl<K: Eq + Hash + Clone + Ord, V> Send for SyncMapImpl<K, V>
this is safety, dirty mutex ensure
impl<K: Eq + Hash + Clone + Ord, V> Sync for SyncMapImpl<K, V>
this is safety, dirty mutex ensure
Auto Trait Implementations
impl<K, V> !RefUnwindSafe for SyncMapImpl<K, V>
impl<K, V> Unpin for SyncMapImpl<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> !UnwindSafe for SyncMapImpl<K, V>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more