Struct string_interner::StringInterner
[−]
[src]
pub struct StringInterner<Sym, H = RandomState> where
Sym: Symbol,
H: BuildHasher, { /* fields omitted */ }
Provides a bidirectional mapping between String stored within the interner and indices. The main purpose is to store every unique String only once and make it possible to reference it via lightweight indices.
Compilers often use this for implementing a symbol table.
The main goal of this StringInterner
is to store String
with as low memory overhead as possible.
Methods
impl<Sym> StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,
fn new() -> StringInterner<Sym, RandomState>
Creates a new empty StringInterner
.
fn with_capacity(cap: usize) -> Self
Creates a new StringInterner
with the given initial capacity.
impl<Sym, H> StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
fn with_hasher(hash_builder: H) -> StringInterner<Sym, H>
Creates a new empty StringInterner
with the given hasher.
fn with_capacity_and_hasher(
cap: usize,
hash_builder: H
) -> StringInterner<Sym, H>
cap: usize,
hash_builder: H
) -> StringInterner<Sym, H>
Creates a new empty StringInterner
with the given initial capacity and the given hasher.
fn get_or_intern<T>(&mut self, val: T) -> Sym where
T: Into<String> + AsRef<str>,
T: Into<String> + AsRef<str>,
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).
fn resolve(&self, symbol: Sym) -> Option<&str>
Returns a string slice to the string identified by the given symbol if available. Else, None is returned.
unsafe fn resolve_unchecked(&self, symbol: Sym) -> &str
Returns a string slice to the string identified by the given symbol, without doing bounds checking. So use it very carefully!
fn get<T>(&self, val: T) -> Option<Sym> where
T: AsRef<str>,
T: AsRef<str>,
Returns the given string's symbol for this interner if existent.
fn len(&self) -> usize
Returns the number of uniquely stored Strings interned within this interner.
fn is_empty(&self) -> bool
Returns true if the string interner internes no elements.
fn iter(&self) -> Iter<Sym>
Returns an iterator over the interned strings.
fn iter_values(&self) -> Values<Sym>
Returns an iterator over all intern indices and their associated strings.
fn clear(&mut self)
Removes all interned Strings from this interner.
This invalides all Symbol
entities instantiated by it so far.
Trait Implementations
impl<Sym, H> Serialize for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher + Default,
[src]
Sym: Symbol,
H: BuildHasher + Default,
fn deserialize<D>(deserializer: D) -> Result<StringInterner<Sym, H>, D::Error> where
D: Deserializer<'de>,
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<Sym> Send for StringInterner<Sym> where
Sym: Symbol + Send,
[src]
Sym: Symbol + Send,
impl<Sym> Sync for StringInterner<Sym> where
Sym: Symbol + Sync,
[src]
Sym: Symbol + Sync,
impl<Sym: Debug, H: Debug> Debug for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
impl<Sym: Clone, H: Clone> Clone for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
fn clone(&self) -> StringInterner<Sym, H>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<Sym: Eq, H: Eq> Eq for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
impl<Sym, H> PartialEq for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
fn eq(&self, rhs: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl Default for StringInterner<usize, RandomState>
[src]
impl<Sym, H> IntoIterator for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,