pub struct BucketTable<V> { /* private fields */ }Expand description
Lock-free fixed-capacity concurrent map: byte-key -> Arc<V>.
Implementations§
Source§impl<V> BucketTable<V>
impl<V> BucketTable<V>
Sourcepub fn with_max_keys(max_keys: usize) -> Self
pub fn with_max_keys(max_keys: usize) -> Self
Build a table sized for at most max_keys live entries. CAP is the next
power of two at or above ceil(max_keys * 4 / 3), then bumped to
guarantee CAP > max_keys so a probe that misses always hits an Empty
slot.
This is the only constructor: a single-parameter type does not earn a
separate new + builder surface (the principle-4 fluent-surface
exception for one mandatory parameter), so with_max_keys is both the
terse and the fluent form.
pub fn is_empty(&self) -> bool
Sourcepub fn get_or_insert(&self, key: &[u8], make: impl FnOnce() -> V) -> Arc<V> ⓘ
pub fn get_or_insert(&self, key: &[u8], make: impl FnOnce() -> V) -> Arc<V> ⓘ
Return the shared handle for key, inserting one made by make if
absent. Concurrent callers racing the same key converge on one published
handle via a single install CAS (the loser re-probes onto the winner’s
entry). make runs at most once per call — lazily, only on a confirmed
miss, and the built Full is reused across CAS retries — and never on a
read hit. If make panics nothing has been installed, so the table is
left unchanged (no stranded slot).
Sourcepub fn get(&self, key: &[u8], hash: u64) -> Option<Arc<V>>
pub fn get(&self, key: &[u8], hash: u64) -> Option<Arc<V>>
Read-only lookup: the shared handle for key, or None if absent. Stops
at the first Empty (proof of absence), probing past Tomb and
non-matching Full. This is the hot path — a lock-free load per slot
and an Arc clone on a hit, no allocation.
Sourcepub fn evict_one_lru(&self, metric: impl Fn(&V) -> u64)
pub fn evict_one_lru(&self, metric: impl Fn(&V) -> u64)
Evict the Full slot whose metric is the strict minimum. Ties resolve
to the LOWEST slot index (deterministic — a divergence from dashmap’s
nondeterministic iteration-order tie-break, documented intentionally).
Best-effort: if the victim changed underneath the CAS it is skipped
(matches dashmap’s non-atomic evict).
Sourcepub fn clear(&self)
pub fn clear(&self)
Tombstone every currently published entry.
This is a best-effort concurrent clear: entries racing with a clear may survive if they are installed after their slot is scanned. Reads remain lock-free, and each successful removal uses the same CAS as eviction so a racing insert is never deleted accidentally.