struct BucketState<const N: usize, const CAP: usize, C: Count> {
counts: [C; N],
}
Expand description
Common implementation for key/value and value-only bucket arrays
Tracks the number of items in each bucket. This is used by BucketArray
and BucketArrayPair
implementations to safely access only initialized
items in the BucketArrayMemory
.
Fields§
§counts: [C; N]
Number of initialized items in each bucket
Each bucket B’s valid item range would be (0 .. counts[B])
Implementations§
Source§impl<const N: usize, const CAP: usize, C: Count> BucketState<N, CAP, C>
impl<const N: usize, const CAP: usize, C: Count> BucketState<N, CAP, C>
Sourcefn new() -> Self
fn new() -> Self
Create a new counter store.
This will happen inside the lifetime of our mutable reference to the backing store memory.
Sourcefn insert<F: FnMut(usize)>(
&mut self,
bucket: usize,
writer: F,
) -> Result<(), ()>
fn insert<F: FnMut(usize)>( &mut self, bucket: usize, writer: F, ) -> Result<(), ()>
Append a new item to a specific bucket using a writer callback.
The writer is invoked with an item index, after checking bucket capacity but before marking the new item as written.
The writer must unconditionally write to the index it’s given, in each of the backing memories covered by this state tracker.
Sourcefn item_range(&self, bucket: usize) -> Range<usize>
fn item_range(&self, bucket: usize) -> Range<usize>
Look up the valid item range for a particular bucket.
Panics if the bucket index is out of range. Item indices inside the returned range are initialized, and any outside may be uninitialized.