pub struct Table<T, D>where
D: SymbolId,{ /* private fields */ }
Expand description
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()
.
Implementations§
Source§impl<T, D> Table<T, D>where
D: SymbolId,
impl<T, D> Table<T, D>where
D: SymbolId,
Sourcepub fn insert(&mut self, value: T) -> &Symbol<T, D>
pub 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.
Sourcepub fn remap<F>(&mut self, f: F)
pub fn remap<F>(&mut self, f: F)
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
.