Struct Table

Source
pub struct Table<T, D>
where D: SymbolId,
{ /* private fields */ }
Expand description

The head of a linked list associating Ts with SymbolIds. 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’s address does not change as long as its parent table exists and it is not dropped from the table.

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,

Source

pub fn new() -> Self

Creates a new, empty table.

Source

pub fn len(&self) -> usize

Returns the number of symbols in the table.

Source

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.

Source

pub fn remap<F>(&mut self, f: F)
where F: FnMut(&Symbol<T, D>) -> Option<D>,

Remaps associations between Ts and Ds, 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 Ts are associated with the same D.

Source

pub fn into_iter(self) -> TableIntoIter<T, D>

Source

pub fn iter<'s>(&'s self) -> TableIter<'s, T, D>

Returns an iterator over table entries.

Source§

impl<T, D> Table<T, D>
where T: Eq + Hash, D: SymbolId,

Source

pub 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§

Source§

impl<T: Debug, D> Debug for Table<T, D>
where D: SymbolId + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T, D> IntoIterator for &'a Table<T, D>
where T: 'a, D: 'a + SymbolId,

Source§

type Item = &'a Symbol<T, D>

The type of the elements being iterated over.
Source§

type IntoIter = TableIter<'a, T, D>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, D> IntoIterator for Table<T, D>
where D: SymbolId,

Source§

type Item = Box<Symbol<T, D>>

The type of the elements being iterated over.
Source§

type IntoIter = TableIntoIter<T, D>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, D> Freeze for Table<T, D>
where D: Freeze,

§

impl<T, D> RefUnwindSafe for Table<T, D>

§

impl<T, D> Send for Table<T, D>
where T: Send,

§

impl<T, D> Sync for Table<T, D>
where T: Sync,

§

impl<T, D> Unpin for Table<T, D>
where D: Unpin,

§

impl<T, D> UnwindSafe for Table<T, D>
where D: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.