pub struct MapCharge { /* private fields */ }Expand description
Charges a concurrent map’s new keys: each key’s owned bytes, and the growth of the map’s table. The table stays charged after its entries are removed, because the map keeps its allocation.
Implementations§
Source§impl MapCharge
impl MapCharge
pub const fn new(owner: Owner, slot_bytes: usize) -> Self
Sourcepub fn ensure<K, Q, V, S>(
&self,
map: &DashMap<K, V, S>,
key: &Q,
to_key: impl FnOnce() -> K,
value: impl FnOnce() -> V,
owned_bytes: u64,
)
pub fn ensure<K, Q, V, S>( &self, map: &DashMap<K, V, S>, key: &Q, to_key: impl FnOnce() -> K, value: impl FnOnce() -> V, owned_bytes: u64, )
Insert key with value if it is absent, charging a new key once.
pub fn release_owned(&self, bytes: u64)
Sourcepub fn forget<K, Q, V, S>(
&self,
map: &DashMap<K, V, S>,
key: &Q,
owned_bytes: u64,
)
pub fn forget<K, Q, V, S>( &self, map: &DashMap<K, V, S>, key: &Q, owned_bytes: u64, )
Remove key from map and release its owned bytes if it was present.
The removal happens inside the call, so two removers cannot both release.
Sourcepub fn clear_owned(&self)
pub fn clear_owned(&self)
Release every owned byte, for a map cleared as a whole.
Sourcepub fn insert<K, V, S>(
&self,
map: &DashMap<K, V, S>,
key: K,
value: V,
measure: impl Fn(&K, &V) -> u64,
)
pub fn insert<K, V, S>( &self, map: &DashMap<K, V, S>, key: K, value: V, measure: impl Fn(&K, &V) -> u64, )
Insert value under key, replacing any previous value. The entry’s
heap is measure(key, value), and the table growth is charged too.
Sourcepub fn upsert<K, V, S, R>(
&self,
map: &DashMap<K, V, S>,
key: K,
fresh: impl FnOnce() -> V,
measure: impl Fn(&K, &V) -> u64,
update: impl FnOnce(&mut V) -> R,
) -> R
pub fn upsert<K, V, S, R>( &self, map: &DashMap<K, V, S>, key: K, fresh: impl FnOnce() -> V, measure: impl Fn(&K, &V) -> u64, update: impl FnOnce(&mut V) -> R, ) -> R
Run update on the entry under key, first inserting fresh() if the
key is absent. The insert, its charge and update run under one entry
guard, so a concurrent remove_entry either sees the entry with its
bytes charged or runs before the insert. update may change the value’s
heap; the charge follows the value’s measure before and after it.
Sourcepub fn owned_bytes(&self) -> u64
pub fn owned_bytes(&self) -> u64
Bytes charged to the entries’ owned heap, excluding the table.
Sourcepub fn remove_entry<K, Q, V, S>(
&self,
map: &DashMap<K, V, S>,
key: &Q,
measure: impl Fn(&K, &V) -> u64,
) -> Option<V>
pub fn remove_entry<K, Q, V, S>( &self, map: &DashMap<K, V, S>, key: &Q, measure: impl Fn(&K, &V) -> u64, ) -> Option<V>
Remove key and release the heap its entry held.
Sourcepub fn remove_entry_if<K, Q, V, S>(
&self,
map: &DashMap<K, V, S>,
key: &Q,
remove_when: impl FnOnce(&V) -> bool,
measure: impl Fn(&K, &V) -> u64,
) -> Option<V>
pub fn remove_entry_if<K, Q, V, S>( &self, map: &DashMap<K, V, S>, key: &Q, remove_when: impl FnOnce(&V) -> bool, measure: impl Fn(&K, &V) -> u64, ) -> Option<V>
Remove key when remove_when holds for its value, releasing the entry’s heap.
Sourcepub fn resize<K, V, S>(&self, map: &DashMap<K, V, S>)
pub fn resize<K, V, S>(&self, map: &DashMap<K, V, S>)
Re-read every shard’s table after a change made without this API.
Sourcepub fn adjust_owned(&self, before: u64, after: u64)
pub fn adjust_owned(&self, before: u64, after: u64)
Charge or release the heap change of a value the map holds in place.