[][src]Struct arc_string_interner::StringInterner

pub struct StringInterner<S, H = RandomState> where
    S: Symbol,
    H: BuildHasher
{ /* fields omitted */ }

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.

Methods

impl<S> StringInterner<S> where
    S: Symbol
[src]

pub fn new() -> StringInterner<S, RandomState>[src]

Creates a new empty StringInterner.

pub fn with_capacity(cap: usize) -> Self[src]

Creates a new StringInterner with the given initial capacity.

pub fn capacity(&self) -> usize[src]

Returns the number of elements the StringInterner can hold without reallocating.

pub fn reserve(&mut self, additional: usize)[src]

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.

impl<S, H> StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

pub fn with_hasher(hash_builder: H) -> StringInterner<S, H>[src]

Creates a new empty StringInterner with the given hasher.

pub fn with_capacity_and_hasher(
    cap: usize,
    hash_builder: H
) -> StringInterner<S, H>
[src]

Creates a new empty StringInterner with the given initial capacity and the given hasher.

pub fn get_or_intern<T>(&mut self, val: T) -> S where
    T: Into<String> + AsRef<str>, 
[src]

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).

pub fn resolve(&self, symbol: S) -> Option<&Arc<str>>[src]

Returns the string slice associated with the given symbol if available, otherwise returns None.

pub unsafe fn resolve_unchecked(&self, symbol: S) -> &Arc<str>[src]

Returns the string associated with the given symbol.

Note

This does not check whether the given symbol has an associated string for the given string interner instance.

Safety

This will result in undefined behaviour if the given symbol had no associated string for this interner instance.

pub fn get<T>(&self, val: T) -> Option<S> where
    T: AsRef<str>, 
[src]

Returns the symbol associated with the given string for this interner if existent, otherwise returns None.

pub fn len(&self) -> usize[src]

Returns the number of uniquely interned strings within this interner.

pub fn is_empty(&self) -> bool[src]

Returns true if the string interner holds no elements.

pub fn iter(&self) -> Iter<S>[src]

Returns an iterator over the interned strings.

pub fn iter_values(&self) -> Values<S>[src]

Returns an iterator over all intern indices and their associated strings.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the interner as much as possible.

Trait Implementations

impl<S, H> Clone for StringInterner<S, H> where
    S: Symbol,
    H: Clone + BuildHasher
[src]

impl<S: Debug, H: Debug> Debug for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

impl Default for StringInterner<Sym, RandomState>[src]

impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H> where
    Sym: Symbol,
    H: BuildHasher + Default
[src]

impl<S: Eq, H: Eq> Eq for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

impl<T, S> Extend<T> for StringInterner<S> where
    S: Symbol,
    T: Into<String> + AsRef<str>, 
[src]

impl<T, S> FromIterator<T> for StringInterner<S> where
    S: Symbol,
    T: Into<String> + AsRef<str>, 
[src]

impl<S, H> IntoIterator for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

type Item = (S, Arc<str>)

The type of the elements being iterated over.

type IntoIter = IntoIter<S>

Which kind of iterator are we turning this into?

impl<S, H> PartialEq<StringInterner<S, H>> for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

impl<S, H> Send for StringInterner<S, H> where
    S: Symbol + Send,
    H: BuildHasher
[src]

impl<Sym, H> Serialize for StringInterner<Sym, H> where
    Sym: Symbol,
    H: BuildHasher
[src]

impl<S, H> StructuralEq for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

impl<S, H> Sync for StringInterner<S, H> where
    S: Symbol + Sync,
    H: BuildHasher
[src]

Auto Trait Implementations

impl<S, H> RefUnwindSafe for StringInterner<S, H> where
    H: RefUnwindSafe,
    S: RefUnwindSafe

impl<S, H> Unpin for StringInterner<S, H> where
    H: Unpin,
    S: Unpin

impl<S, H> UnwindSafe for StringInterner<S, H> where
    H: UnwindSafe,
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.