[−][src]Struct hayami::SymbolTable
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
impl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S> where
IndexMap<K, Vec<(V, usize)>, S>: Default,
[src]
IndexMap<K, Vec<(V, usize)>, S>: Default,
pub fn new() -> SymbolTable<K, V, S>
[src]
Create a new, empty symbol table
impl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S> where
S: Default,
[src]
S: Default,
pub fn with_capacity(n: usize) -> SymbolTable<K, V, S>
[src]
Create a symbol table with a given capacity
impl<K: Hash + Eq, V, S: BuildHasher> SymbolTable<K, V, S>
[src]
pub fn with_hasher(hash_builder: S) -> SymbolTable<K, V, S>
[src]
Create a symbol table with a given hasher
pub fn with_capacity_and_hasher(
n: usize,
hash_builder: S
) -> SymbolTable<K, V, S>
[src]
n: usize,
hash_builder: S
) -> SymbolTable<K, V, S>
Create a symbol table with a given capacity and hasher
pub fn depth(&self) -> usize
[src]
Get the current depth
pub fn insert(&mut self, key: K, value: V) -> Option<V>
[src]
Register a given symbol at the current depth, returning the current definition at the current depth, if any.
pub fn try_insert(&mut self, key: K, value: V) -> Result<(), V>
[src]
Try to register a given symbol at the current depth. Fail if the symbol is already defined
pub fn get_full<Q: ?Sized>(&self, key: &Q) -> Option<(&V, usize)> where
Q: Hash + Equivalent<K>,
[src]
Q: Hash + Equivalent<K>,
Get the definition of a current symbol, along with its depth, if any
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
Q: Hash + Equivalent<K>,
[src]
Q: Hash + Equivalent<K>,
Get the definition of a symbol
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
Q: Hash + Equivalent<K>,
[src]
Q: Hash + Equivalent<K>,
Check whether a symbol has a definition
pub fn get_full_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<(&mut V, usize)> where
Q: Hash + Equivalent<K>,
[src]
Q: Hash + Equivalent<K>,
Mutably get the definition of a current symbol, along with its depth, if any
pub fn try_get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
Q: Hash + Equivalent<K>,
[src]
Q: Hash + Equivalent<K>,
Try to mutably get the definition of a current symbol at the current depth
pub fn jump(&mut self, depth: usize)
[src]
Get the mutable definition of a current symbol, along with its depth, if any Jump to a given depth, removing obsolete definitions. Return the number of keys and definitions removed, as well as keys touched, if any.
pub fn push(&mut self)
[src]
Add a level of depth
pub fn popn(&mut self, n: usize)
[src]
Pop up to n
levels of depth.
pub fn pop(&mut self)
[src]
Try to remove a level of depth. Does nothing if depth = 0
pub fn is_empty(&self) -> bool
[src]
Check whether a symbol table is empty
pub fn reserve(&mut self, additional: usize)
[src]
Reserve space for at least additional
symbols in this symbol table
pub fn capacity(&self) -> usize
[src]
Get the capacity of this symbol table
Trait Implementations
impl<K: Clone + Hash + Eq, V: Clone, S: Clone + BuildHasher> Clone for SymbolTable<K, V, S>
[src]
fn clone(&self) -> SymbolTable<K, V, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K: Hash + Eq + Debug, V: Debug, S: BuildHasher> Debug for SymbolTable<K, V, S>
[src]
impl<K: Hash + Eq, V, S: BuildHasher> Default for SymbolTable<K, V, S> where
IndexMap<K, Vec<(V, usize)>, S>: Default,
[src]
IndexMap<K, Vec<(V, usize)>, S>: Default,
fn default() -> SymbolTable<K, V, S>
[src]
impl<K: Eq + Hash, V: Eq, S: Eq + BuildHasher> Eq for SymbolTable<K, V, S>
[src]
impl<K: PartialEq + Hash + Eq, V: PartialEq, S: PartialEq + BuildHasher> PartialEq<SymbolTable<K, V, S>> for SymbolTable<K, V, S>
[src]
fn eq(&self, other: &SymbolTable<K, V, S>) -> bool
[src]
fn ne(&self, other: &SymbolTable<K, V, S>) -> bool
[src]
impl<K: Hash + Eq, V, S: BuildHasher> StructuralEq for SymbolTable<K, V, S>
[src]
impl<K: Hash + Eq, V, S: BuildHasher> StructuralPartialEq for SymbolTable<K, V, S>
[src]
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for SymbolTable<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, S> Send for SymbolTable<K, V, S> where
K: Send,
S: Send,
V: Send,
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for SymbolTable<K, V, S> where
K: Sync,
S: Sync,
V: Sync,
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> Unpin for SymbolTable<K, V, S> where
K: Unpin,
S: Unpin,
V: Unpin,
K: Unpin,
S: Unpin,
V: Unpin,
impl<K, V, S> UnwindSafe for SymbolTable<K, V, S> where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,