pub struct StringInterner<S, H = RandomState>where
S: Symbol,
H: BuildHasher,{ /* private fields */ }Expand description
Caches strings efficiently, with minimal memory footprint and associates them with unique symbols. These symbols allow constant time comparisons and look-ups to the underlying interned strings.
Implementations§
Source§impl<S> StringInterner<S>where
S: Symbol,
impl<S> StringInterner<S>where
S: Symbol,
Sourcepub fn new() -> StringInterner<S, RandomState>
pub fn new() -> StringInterner<S, RandomState>
Creates a new empty StringInterner.
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates a new StringInterner with the given initial capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the StringInterner can hold without reallocating.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be interned into self.
The collection may reserve more space to avoid frequent allocations.
After calling reserve, capacity will be greater than or equal to self.len() + additional.
Does nothing if capacity is already sufficient.
Source§impl<S, H> StringInterner<S, H>where
S: Symbol,
H: BuildHasher,
impl<S, H> StringInterner<S, H>where
S: Symbol,
H: BuildHasher,
Sourcepub fn with_hasher(hash_builder: H) -> StringInterner<S, H>
pub fn with_hasher(hash_builder: H) -> StringInterner<S, H>
Creates a new empty StringInterner with the given hasher.
Sourcepub fn with_capacity_and_hasher(
cap: usize,
hash_builder: H,
) -> StringInterner<S, H>
pub fn with_capacity_and_hasher( cap: usize, hash_builder: H, ) -> StringInterner<S, H>
Creates a new empty StringInterner with the given initial capacity and the given hasher.
Sourcepub fn get_or_intern<T>(&mut self, val: T) -> S
pub fn get_or_intern<T>(&mut self, val: T) -> S
Interns the given value.
Returns a symbol to access it within this interner.
This either copies the contents of the string (e.g. for str) or moves them into this interner (e.g. for String).
Sourcepub fn resolve(&self, symbol: S) -> Option<&Arc<str>>
pub fn resolve(&self, symbol: S) -> Option<&Arc<str>>
Returns the string slice associated with the given symbol if available,
otherwise returns None.
Sourcepub unsafe fn resolve_unchecked(&self, symbol: S) -> &Arc<str>
pub unsafe fn resolve_unchecked(&self, symbol: S) -> &Arc<str>
Sourcepub fn get<T>(&self, val: T) -> Option<S>
pub fn get<T>(&self, val: T) -> Option<S>
Returns the symbol associated with the given string for this interner
if existent, otherwise returns None.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of uniquely interned strings within this interner.
Sourcepub fn iter_values(&self) -> Values<'_, S> ⓘ
pub fn iter_values(&self) -> Values<'_, S> ⓘ
Returns an iterator over all intern indices and their associated strings.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the interner as much as possible.
Trait Implementations§
Source§impl<S, H> Clone for StringInterner<S, H>
impl<S, H> Clone for StringInterner<S, H>
Source§impl<S, H> Debug for StringInterner<S, H>
impl<S, H> Debug for StringInterner<S, H>
Source§impl Default for StringInterner<Sym, RandomState>
impl Default for StringInterner<Sym, RandomState>
Source§impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H>
impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H>
Source§fn deserialize<D>(deserializer: D) -> Result<StringInterner<Sym, H>, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<StringInterner<Sym, H>, D::Error>where
D: Deserializer<'de>,
Source§impl<T, S> Extend<T> for StringInterner<S>
impl<T, S> Extend<T> for StringInterner<S>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)