pub struct StringPool { /* private fields */ }Expand description
A string pool that deduplicates strings using reference counting.
Strings are stored as Arc<str>, allowing multiple references to
the same string without duplication. The pool maintains a weak
reference to each string, allowing unused strings to be garbage
collected.
Implementations§
Source§impl StringPool
impl StringPool
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a string pool with the specified capacity.
Sourcepub fn intern(&mut self, s: &str) -> Arc<str>
pub fn intern(&mut self, s: &str) -> Arc<str>
Interns a string, returning a reference-counted handle.
If the string already exists in the pool, returns a clone of
the existing Arc<str>. Otherwise, creates a new entry.
Sourcepub fn intern_string(&mut self, s: String) -> Arc<str>
pub fn intern_string(&mut self, s: String) -> Arc<str>
Interns a string from an owned String.
This is more efficient than intern when you already have a String,
as it avoids an extra allocation if the string is not already pooled.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Returns the memory usage of the pool in bytes (approximate).
This includes the HashMap overhead and the string data.
Sourcepub fn stats(&self) -> StringPoolStats
pub fn stats(&self) -> StringPoolStats
Returns statistics about the string pool.