pub struct StringInterner { /* private fields */ }Expand description
A thread-safe string interner that deduplicates strings with ID mapping
Integrates SciRS2-core metrics for production-grade performance monitoring:
- Automatic cache hit/miss tracking
- Intern operation timing
- Memory usage histograms
- Deduplication effectiveness metrics
Implementations§
Source§impl StringInterner
impl StringInterner
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new string interner with ID mapping and SciRS2 metrics
Automatically tracks:
- Cache hit/miss rates for intern operations
- Operation timing for performance analysis
- String length distribution
- Memory usage patterns
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new string interner with specified capacity
Pre-allocates HashMaps to the given capacity to reduce reallocation overhead. Initializes all SciRS2 metrics for comprehensive monitoring.
Sourcepub fn intern(&self, s: &str) -> Arc<str>
pub fn intern(&self, s: &str) -> Arc<str>
Intern a string, returning an Arc<str> that can be cheaply cloned and compared
This operation is tracked with SciRS2 metrics:
- Cache hits/misses
- Operation timing
- String length distribution
Sourcepub fn intern_with_id(&self, s: &str) -> (Arc<str>, u32)
pub fn intern_with_id(&self, s: &str) -> (Arc<str>, u32)
Intern a string and return both the Arc<str> and its numeric ID
Sourcepub fn get_all_mappings(&self) -> Vec<(u32, Arc<str>)>
pub fn get_all_mappings(&self) -> Vec<(u32, Arc<str>)>
Get all ID mappings (useful for serialization/debugging)
Sourcepub fn cleanup(&self) -> usize
pub fn cleanup(&self) -> usize
Clean up expired weak references to save memory
Returns the number of entries cleaned up
Sourcepub fn stats(&self) -> InternerStats
pub fn stats(&self) -> InternerStats
Get current statistics
Sourcepub fn id_mapping_count(&self) -> usize
pub fn id_mapping_count(&self) -> usize
Get the number of strings with ID mappings
Sourcepub fn intern_batch(&self, strings: &[&str]) -> Vec<Arc<str>>
pub fn intern_batch(&self, strings: &[&str]) -> Vec<Arc<str>>
Batch intern multiple strings for improved performance
Returns a Vec of Arc<str> in the same order as input
Sourcepub fn prefetch(&self, strings: &[&str])
pub fn prefetch(&self, strings: &[&str])
Prefetch strings into the interner cache for improved performance This is useful when you know you’ll need certain strings soon
Sourcepub fn memory_usage(&self) -> MemoryUsage
pub fn memory_usage(&self) -> MemoryUsage
Get memory usage statistics for performance monitoring
Sourcepub fn get_metrics(&self) -> InternerMetrics
pub fn get_metrics(&self) -> InternerMetrics
Get comprehensive performance metrics from SciRS2
Returns detailed statistics including:
- Cache hit/miss counts and ratios
- Operation timing statistics
- String length distribution
- Memory usage patterns
Trait Implementations§
Source§impl Debug for StringInterner
impl Debug for StringInterner
Auto Trait Implementations§
impl !Freeze for StringInterner
impl RefUnwindSafe 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
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