pub struct StringInterner { /* private fields */ }Expand description
A thread-safe interner that deduplicates strings into Arc<str>.
Internally backed by a DashMap which provides lock-free concurrent
reads with per-shard locking for writes, eliminating the global
RwLock contention bottleneck.
§Example
use chronix_engine::memtable::interner::StringInterner;
let interner = StringInterner::new();
let a = interner.intern("cpu");
let b = interner.intern("cpu");
assert!(std::sync::Arc::ptr_eq(&a, &b));Implementations§
Source§impl StringInterner
impl StringInterner
Sourcepub fn intern(&self, s: &str) -> Arc<str> ⓘ
pub fn intern(&self, s: &str) -> Arc<str> ⓘ
Intern a string, returning a shared Arc<str>.
If the string has been seen before, the existing Arc is cloned
(lock-free read via DashMap shard). Otherwise, a new Arc<str>
is allocated and inserted (per-shard write lock only).
Sourcepub fn lookup(&self, s: &str) -> Option<Arc<str>>
pub fn lookup(&self, s: &str) -> Option<Arc<str>>
Look up a previously interned string without inserting.
Returns Some(Arc<str>) if the string was already interned,
None otherwise.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Approximate heap bytes held by the interner.
The interned strings themselves plus the map’s per-entry overhead: an
Arc<str> header (two usize counts), the fat pointer the map stores,
and a hash slot. Interned strings are tag keys, tag values and
measurement names, so on a high-cardinality workload this is the term
that grows, and on the gateway it is one of the three that the memtable
budget does not count.
Trait Implementations§
Source§impl Debug for StringInterner
impl Debug for StringInterner
Auto Trait Implementations§
impl !RefUnwindSafe for StringInterner
impl Freeze for StringInterner
impl Send for StringInterner
impl Sync for StringInterner
impl Unpin for StringInterner
impl UnsafeUnpin for StringInterner
impl UnwindSafe for StringInterner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more