pub struct StringPool { /* private fields */ }Expand description
A string interning pool.
Stores each unique string exactly once and returns lightweight handles
(InternedString) for fast comparison.
Implementations§
Source§impl StringPool
impl StringPool
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a pool pre-sized for the given capacity.
Sourcepub fn intern(&mut self, s: &str) -> InternedString
pub fn intern(&mut self, s: &str) -> InternedString
Intern a string. If the string is already in the pool, returns the existing handle. Otherwise inserts it and returns a new handle.
Sourcepub fn intern_bulk(&mut self, strs: &[&str]) -> Vec<InternedString>
pub fn intern_bulk(&mut self, strs: &[&str]) -> Vec<InternedString>
Intern multiple strings at once, returning handles in the same order.
Sourcepub fn intern_iter<'a, I>(&mut self, iter: I) -> Vec<InternedString>where
I: IntoIterator<Item = &'a str>,
pub fn intern_iter<'a, I>(&mut self, iter: I) -> Vec<InternedString>where
I: IntoIterator<Item = &'a str>,
Intern strings from an iterator.
Sourcepub fn resolve(&self, id: InternedString) -> Option<&str>
pub fn resolve(&self, id: InternedString) -> Option<&str>
Resolve an interned string back to its content.
Sourcepub fn lookup(&self, s: &str) -> Option<InternedString>
pub fn lookup(&self, s: &str) -> Option<InternedString>
Look up an interned string by content. Returns None if the string
has not been interned.
Sourcepub fn statistics(&self) -> &PoolStatistics
pub fn statistics(&self) -> &PoolStatistics
Get pool statistics.
Sourcepub fn snapshot(&self) -> PoolSnapshot
pub fn snapshot(&self) -> PoolSnapshot
Create a snapshot of the pool for serialization.
Sourcepub fn iter(&self) -> impl Iterator<Item = (InternedString, &str)>
pub fn iter(&self) -> impl Iterator<Item = (InternedString, &str)>
Iterate over all interned strings with their handles.
Sourcepub fn merge(&mut self, other: &StringPool) -> Vec<InternedString>
pub fn merge(&mut self, other: &StringPool) -> Vec<InternedString>
Merge another pool into this one. Returns a mapping from old indices to new indices.