Struct symbol_map::Table
[−]
[src]
pub struct Table<T, D> where D: SymbolId {
// some fields omitted
}
The head of a linked list associating T
s with SymbolId
s. SymbolId
values start at 0 and increase by 1 for each T
added to the table.
The linked list owns instances of Symbol<T>
, which wrap around a T
and a
SymbolId
. It satisfies the contract: once allocated, a Symbol
As a result, a table index may retain a raw pointer to a Symbol<T>
as long
as care is taken not to dereference or otherwise make use of such pointers
after the symbol they point to has been dropped by retain()
.
Methods
impl<T, D> Table<T, D> where D: SymbolId
[src]
fn new() -> Self
Creates a new, empty table.
fn len(&self) -> usize
Returns the number of symbols in the table.
fn insert(&mut self, value: T) -> &Symbol<T, D>
Inserts value
into the table and assigns it an id. The same value may
be inserted more than once. To prevent such operations, use the
get_or_insert()
method of Indexing
.
Returns a reference to the newly created symbol.
fn remap<F>(&mut self, f: F) where F: FnMut(&Symbol<T, D>) -> Option<D>
Remaps associations between T
s and D
s, selectively dropping some
associations entirely. The addresses of Symbol<T>
s for entries which
are retained do not change.
(T, D)
associations for which f
returns Some(d)
will be remapped
to use d
.
(T, D)
associations for which f
returns None
will be dropped.
It is the responsibility of the caller to maintain the following:
The final mapping should be a dense range of whole numbers starting at 0.
No two different
T
s are associated with the sameD
.
fn into_iter(self) -> TableIntoIter<T, D>
fn iter<'s>(&'s self) -> TableIter<'s, T, D>
Returns an iterator over table entries.
impl<T, D> Table<T, D> where T: Eq + Hash, D: SymbolId
[src]
fn to_hash_map(self) -> HashMap<T, D>
Converts self
to a HashMap
holding the same associations as
self
. If the same key occurs in self
more than once, then duplicate
occurrences will be dropped arbitrarily.
Trait Implementations
impl<'a, T, D> IntoIterator for &'a Table<T, D> where T: 'a, D: 'a + SymbolId
[src]
type Item = &'a Symbol<T, D>
The type of the elements being iterated over.
type IntoIter = TableIter<'a, T, D>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more