pub struct ShardedCountAndSize { /* private fields */ }Expand description
Reduces contention when counting live items and their total size across threads.
Updates are keyed by item identity, allowing different threads to add and remove an item without accumulating per-thread imbalances. Construction and updates never allocate memory.
Implementations§
Source§impl ShardedCountAndSize
impl ShardedCountAndSize
Sourcepub fn add(&self, key: usize, size: usize)
pub fn add(&self, key: usize, size: usize)
Adds an item. Use the same key and size when removing it.
The live item count and combined size must not exceed usize::MAX.
Updates wrap on overflow.
Sourcepub fn sub(&self, key: usize, size: usize)
pub fn sub(&self, key: usize, size: usize)
Removes a previously added item, using its original key and size.
Sourcepub fn load(&self) -> CountAndSize
pub fn load(&self) -> CountAndSize
Returns sampled totals, exact when updates are idle.
Concurrent updates may make the count and size each overestimate or
underestimate the true value independently. Totals saturate at
usize::MAX instead of overflowing.
Sourcepub fn load_size(&self) -> usize
pub fn load_size(&self) -> usize
Returns the sampled total size, with the same semantics as Self::load.