Struct hayami::SymbolTable
source · [−]pub struct SymbolTable<K: Hash + Eq, V, S: BuildHasher = RandomState> { /* private fields */ }
Expand description
A simple, generic symbol table.
Behaves like a stack of HashMap
s, where you can only insert symbols into the top map with insert
. When a symbol is
looked up with get
, first the top map is checked, then the map under it, etc., with the first match found returned.
This is implemented more efficiently using an IndexMap
. get_full
does the same, but returns the depth at which the
symbol was found.
Implementations
sourceimpl<K: Hash + Eq, V> SymbolTable<K, V>
impl<K: Hash + Eq, V> SymbolTable<K, V>
sourcepub fn new() -> SymbolTable<K, V>
pub fn new() -> SymbolTable<K, V>
Create a new, empty symbol table
sourceimpl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S>where
S: Default,
impl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S>where
S: Default,
sourcepub fn with_capacity(n: usize) -> SymbolTable<K, V, S>
pub fn with_capacity(n: usize) -> SymbolTable<K, V, S>
Create a symbol table with a given capacity
sourceimpl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S>
sourcepub fn with_hasher(hash_builder: S) -> SymbolTable<K, V, S>
pub fn with_hasher(hash_builder: S) -> SymbolTable<K, V, S>
Create a symbol table with a given hasher
sourcepub fn with_capacity_and_hasher(
n: usize,
hash_builder: S
) -> SymbolTable<K, V, S>
pub fn with_capacity_and_hasher(
n: usize,
hash_builder: S
) -> SymbolTable<K, V, S>
Create a symbol table with a given capacity and hasher
sourcepub fn try_insert(&mut self, key: K, value: V) -> Result<(), V>
pub fn try_insert(&mut self, key: K, value: V) -> Result<(), V>
Try to register a given symbol at the current depth. Fail if the symbol is already defined
sourcepub fn get_defs<Q>(&self, key: &Q) -> &[(V, usize)]where
Q: ?Sized + Hash + Equivalent<K>,
pub fn get_defs<Q>(&self, key: &Q) -> &[(V, usize)]where
Q: ?Sized + Hash + Equivalent<K>,
Get the definition of a current symbol, along with its depth, if any
sourcepub fn get_full<Q>(&self, key: &Q) -> Option<(&V, usize)>where
Q: ?Sized + Hash + Equivalent<K>,
pub fn get_full<Q>(&self, key: &Q) -> Option<(&V, usize)>where
Q: ?Sized + Hash + Equivalent<K>,
Get the definition of a current symbol, along with its depth, if any
sourcepub fn contains_key<Q>(&self, key: &Q) -> boolwhere
Q: ?Sized + Hash + Equivalent<K>,
pub fn contains_key<Q>(&self, key: &Q) -> boolwhere
Q: ?Sized + Hash + Equivalent<K>,
Check whether a symbol has a definition
sourcepub fn get_full_mut<Q>(&mut self, key: &Q) -> Option<(&mut V, usize)>where
Q: ?Sized + Hash + Equivalent<K>,
pub fn get_full_mut<Q>(&mut self, key: &Q) -> Option<(&mut V, usize)>where
Q: ?Sized + Hash + Equivalent<K>,
Mutably get the definition of a current symbol, along with its depth, if any
sourcepub fn jump(&mut self, depth: usize)
pub fn jump(&mut self, depth: usize)
Jump to a given depth, removing obsolete definitions. Return the number of keys and definitions removed, as well as keys touched, if any.
Trait Implementations
sourceimpl<K: Clone + Hash + Eq, V: Clone, S: Clone + BuildHasher> Clone for SymbolTable<K, V, S>
impl<K: Clone + Hash + Eq, V: Clone, S: Clone + BuildHasher> Clone for SymbolTable<K, V, S>
sourcefn clone(&self) -> SymbolTable<K, V, S>
fn clone(&self) -> SymbolTable<K, V, S>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<K: Hash + Eq + Debug, V: Debug, S: BuildHasher> Debug for SymbolTable<K, V, S>
impl<K: Hash + Eq + Debug, V: Debug, S: BuildHasher> Debug for SymbolTable<K, V, S>
sourceimpl<K: Hash + Eq, V, S: BuildHasher> Default for SymbolTable<K, V, S>where
IndexMap<K, Vec<(V, usize)>, S>: Default,
impl<K: Hash + Eq, V, S: BuildHasher> Default for SymbolTable<K, V, S>where
IndexMap<K, Vec<(V, usize)>, S>: Default,
sourcefn default() -> SymbolTable<K, V, S>
fn default() -> SymbolTable<K, V, S>
sourceimpl<K: Hash + Eq, V, S: BuildHasher> MutSymbolMap<K> for SymbolTable<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher> MutSymbolMap<K> for SymbolTable<K, V, S>
sourceimpl<K: PartialEq + Hash + Eq, V: PartialEq, S: PartialEq + BuildHasher> PartialEq<SymbolTable<K, V, S>> for SymbolTable<K, V, S>
impl<K: PartialEq + Hash + Eq, V: PartialEq, S: PartialEq + BuildHasher> PartialEq<SymbolTable<K, V, S>> for SymbolTable<K, V, S>
sourcefn eq(&self, other: &SymbolTable<K, V, S>) -> bool
fn eq(&self, other: &SymbolTable<K, V, S>) -> bool
sourceimpl<K: Hash + Eq, V, S: BuildHasher> SymbolMap<K> for SymbolTable<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher> SymbolMap<K> for SymbolTable<K, V, S>
type Value = V
type Value = V
sourcefn get<Q>(&self, key: &Q) -> Option<&V>where
Q: ?Sized + Hash + Eq,
K: Borrow<Q>,
fn get<Q>(&self, key: &Q) -> Option<&V>where
Q: ?Sized + Hash + Eq,
K: Borrow<Q>,
sourcefn insert(&mut self, key: K, value: V)
fn insert(&mut self, key: K, value: V)
sourcefn try_get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where
Q: ?Sized + Hash + Equivalent<K>,
fn try_get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where
Q: ?Sized + Hash + Equivalent<K>,
impl<K: Eq + Hash + Eq, V: Eq, S: Eq + BuildHasher> Eq for SymbolTable<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher> StructuralEq for SymbolTable<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher> StructuralPartialEq for SymbolTable<K, V, S>
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for SymbolTable<K, V, S>where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, S> Send for SymbolTable<K, V, S>where
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for SymbolTable<K, V, S>where
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> Unpin for SymbolTable<K, V, S>where
K: Unpin,
S: Unpin,
V: Unpin,
impl<K, V, S> UnwindSafe for SymbolTable<K, V, S>where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.