Trait symbol_map::indexing::Indexing
[−]
[src]
pub trait Indexing: Default { type Data; type Id: SymbolId; fn from_table(table: Table<Self::Data, Self::Id>) -> Self; fn table(&self) -> &Table<Self::Data, Self::Id>; fn to_table(self) -> Table<Self::Data, Self::Id>; fn get(&self, data: &Self::Data) -> Option<&Symbol<Self::Data, Self::Id>>; fn get_or_insert<'s>(&'s mut self, data: Self::Data) -> Insertion<&'s Symbol<Self::Data, Self::Id>>; fn get_symbol<'s>(&'s self, id: &Self::Id) -> Option<&'s Symbol<Self::Data, Self::Id>>; }
Provides indexing for a Table
, so that its elements may be retrieved
efficiently. Most table lookups should go through an implementation of this
trait structure instead of a Table
directly.
An Indexing
should own an underlying Table<Indexing::Data>
. This table
provides persistent storage for Symbol<Indexing::Data>
s, which associate
instances of Data
with a SymbolId
.
This trait is provided for extensibility. Realistically speaking, however,
you should probably just use HashIndexing
.
Associated Types
Required Methods
fn from_table(table: Table<Self::Data, Self::Id>) -> Self
Returns a new indexing method that has already indexed the contents of
table
.
fn table(&self) -> &Table<Self::Data, Self::Id>
Returns a read-only view of the underlying table.
fn to_table(self) -> Table<Self::Data, Self::Id>
Extracts the underlying table from the index, discarding all pointers into the table.
fn get(&self, data: &Self::Data) -> Option<&Symbol<Self::Data, Self::Id>>
Looks up data
in the index. Returns Some(&symbol)
if a symbol is
present, else None
.
fn get_or_insert<'s>(&'s mut self, data: Self::Data) -> Insertion<&'s Symbol<Self::Data, Self::Id>>
Looks up data
in the index, inserting it into the index and table
if
it isn't present. Returns the resulting &Symbol<T>
wrapped in an
Insertion
that indicates whether a new table entry had to be created.
fn get_symbol<'s>(&'s self, id: &Self::Id) -> Option<&'s Symbol<Self::Data, Self::Id>>
Looks up the symbol with id i
in the index. Returns Some(symbol)
if
a symbol is present, else None
.
Implementors
impl<T, D> Indexing for HashIndexing<T, D> where T: Eq + Hash, D: SymbolId