Skip to main content

BucketTable

Struct BucketTable 

Source
pub struct BucketTable<V> { /* private fields */ }
Expand description

Lock-free fixed-capacity concurrent map: byte-key -> Arc<V>.

Implementations§

Source§

impl<V> BucketTable<V>

Source

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.

Source

pub fn len(&self) -> usize

Advisory live-entry count (Relaxed).

Source

pub fn is_empty(&self) -> bool

Source

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).

Source

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.

Source

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).

Source

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.

Source

pub fn sweep_idle(&self, now: u64, ttl: u64, metric: impl Fn(&V) -> u64)

Tombstone every Full slot whose metric is strictly less than now - ttl. A value exactly equal to the cutoff survives.

Auto Trait Implementations§

§

impl<V> !Freeze for BucketTable<V>

§

impl<V> RefUnwindSafe for BucketTable<V>
where Box<[Slot<V>]>: RefUnwindSafe, Arc<SlotState<V>>: RefUnwindSafe,

§

impl<V> Send for BucketTable<V>
where Box<[Slot<V>]>: Send, Arc<SlotState<V>>: Send,

§

impl<V> Sync for BucketTable<V>
where Box<[Slot<V>]>: Sync, Arc<SlotState<V>>: Sync,

§

impl<V> Unpin for BucketTable<V>
where Box<[Slot<V>]>: Unpin, Arc<SlotState<V>>: Unpin,

§

impl<V> UnsafeUnpin for BucketTable<V>
where Box<[Slot<V>]>: UnsafeUnpin, Arc<SlotState<V>>: UnsafeUnpin,

§

impl<V> UnwindSafe for BucketTable<V>
where Box<[Slot<V>]>: UnwindSafe, Arc<SlotState<V>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more