Struct sid::IdFreeList

source ·
pub struct IdFreeList<ID: Identifier, Data, C: NullId<ID>> { /* private fields */ }
Expand description

A linked list stored in contiguous memory allowing random access through ids.

Implementations§

source§

impl<ID: Identifier, Data, C: NullId<ID>> IdFreeList<ID, Data, C>

source

pub fn new() -> IdFreeList<ID, Data, C>

Create an empty list.

source

pub fn with_capacity(size: usize) -> IdFreeList<ID, Data, C>

Create an empty list with a preallocated buffer.

source

pub fn add(&mut self, elt: Data) -> ID

Add an element to the list and return the id pointing to it

source

pub fn push(&mut self, elt: Data) -> ID

Add an element to the list at the end of the vector storage (without attempting to occupy a slot from the free-list). This means that repeated calls to push without calls to add or remove will produce contiguous indices.

source

pub fn remove(&mut self, id: ID)

Remove a given element from the list and place the slot in the free-list. Note that this does not attempt to drop the element.

source

pub fn count(&self) -> usize

Count the elements in O(N).

source

pub fn has_id(&self, id: ID) -> bool

Return true if the id is found in the list in O(N).

source

pub fn is_empty(&self) -> bool

Return true if there is no element in the list.

source

pub fn clear(&mut self)

Remove all elements from the list and clears the storage. Note that this will Drop the elements if Data implements Drop.

source

pub fn next_id(&self, id: ID) -> Option<ID>

Return the next id in the list.

source

pub fn previous_id(&self, id: ID) -> Option<ID>

Return the previous id in the list.

source

pub fn first_id(&self) -> Option<ID>

Return the first id in the list.

Trait Implementations§

source§

impl<ID: Identifier, Data, C: NullId<ID>> Index<ID> for IdFreeList<ID, Data, C>

§

type Output = Data

The returned type after indexing.
source§

fn index<'l>(&'l self, id: ID) -> &'l Data

Performs the indexing (container[index]) operation. Read more
source§

impl<ID: Identifier, Data, C: NullId<ID>> IndexMut<ID> for IdFreeList<ID, Data, C>

source§

fn index_mut<'l>(&'l mut self, id: ID) -> &'l mut Data

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<ID, Data, C> RefUnwindSafe for IdFreeList<ID, Data, C>

§

impl<ID, Data, C> Send for IdFreeList<ID, Data, C>
where C: Send, Data: Send, ID: Send,

§

impl<ID, Data, C> Sync for IdFreeList<ID, Data, C>
where C: Sync, Data: Sync, ID: Sync,

§

impl<ID, Data, C> Unpin for IdFreeList<ID, Data, C>
where C: Unpin, Data: Unpin, ID: Unpin,

§

impl<ID, Data, C> UnwindSafe for IdFreeList<ID, Data, C>
where C: UnwindSafe, Data: UnwindSafe, ID: 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>,

§

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>,

§

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.