Struct alot::unordered::Lots

source ·
pub struct Lots<T> { /* private fields */ }
Expand description

A collection of T, organized by generational LotIds.

This data type allows storing data of any type and receiving a LotId that can later be used to look up the data.

This data type cannot hold more than 2^48 items, due how LotIds are allocated.

Generation Checks

A LotId contains 16 bits representing a lot’s generation. Each time a lot is updated, the lot’s generation is incremented (with wrapping).

The lot’s generation is checked when retrieving data using a LotId. If a generation mismatch is found, the data will not be returned.

While the chances of generation collision may be low, this is not a perfect check. Care should still be taken to ensure stale LotIds aren’t used when other ways of validating the data don’t exist.

Implementations§

source§

impl<T> Lots<T>

source

pub const fn new() -> Self

Returns a new, empty collection.

source

pub fn with_capacity(initial_capacity: usize) -> Self

Returns an empty collection that can hold initial_capacity values without reallocation.

source

pub fn push(&mut self, value: T) -> LotId

Adds value to the collection, returning the value’s unique LotId.

source

pub fn clear(&mut self)

Removes all values from the collection.

source

pub fn get(&self, id: LotId) -> Option<&T>

Looks up a previously stored value by its LotId. If the value hasn’t been removed, a reference will be returned.

Note: It is possible, but unlikely, for a LotId that has been removed to be reused.

source

pub fn get_mut(&mut self, id: LotId) -> Option<&mut T>

Looks up a previously stored value by its LotId. If the value hasn’t been removed, a mutable reference will be returned.

Note: It is possible, but unlikely, for a LotId that has been removed to be reused.

source

pub fn remove(&mut self, id: LotId) -> Option<T>

Removes a previously stored value by its LotId. If the value is present, it will be removed and returned.

Note: It is possible, but unlikely, for a LotId that has been removed to be reused.

source

pub fn drain(&mut self) -> Drain<'_, T, DrainAll>

Returns an iterator that returns all the contained values in this collection as they’re removed from the collection.

Dropping the iterator will still result in the elements being removed.

source

pub fn drain_filter<Filter>(&mut self, filter: Filter) -> Drain<'_, T, Filter>
where Filter: FnMut(&mut T) -> bool,

Returns an iterator that invokes filter for each item in the collection. If filter returns true for that value, it will be removed and returned from the iterator. When false is returned, the value is kept in the collection.

Dropping the iterator will still result in the filtered elements being removed.

source

pub fn len(&self) -> usize

Returns the number of values contained in this collection.

source

pub fn is_empty(&self) -> bool

Returns true if this collection has no values.

source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator of references to all contained values.

source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator of exclusive references to all contained values.

source

pub fn entries(&self) -> EntryIter<'_, T>

Returns an Iterator<Item = (LotId, &T)> for all contained values.

Trait Implementations§

source§

impl<T: Clone> Clone for Lots<T>

source§

fn clone(&self) -> Lots<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Lots<T>
where T: Debug,

source§

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

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

impl<T> Default for Lots<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> FromIterator<T> for Lots<T>

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T> Index<LotId> for Lots<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, id: LotId) -> &Self::Output

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

impl<T> IndexMut<LotId> for Lots<T>

source§

fn index_mut(&mut self, id: LotId) -> &mut Self::Output

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

impl<'a, T> IntoIterator for &'a Lots<T>

§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
§

type Item = &'a T

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, T> IntoIterator for &'a mut Lots<T>

§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
§

type Item = &'a mut T

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Lots<T>

§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
§

type Item = T

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> PartialEq for Lots<T>
where T: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Eq for Lots<T>
where T: Eq,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Lots<T>
where T: RefUnwindSafe,

§

impl<T> Send for Lots<T>
where T: Send,

§

impl<T> Sync for Lots<T>
where T: Sync,

§

impl<T> Unpin for Lots<T>
where T: Unpin,

§

impl<T> UnwindSafe for Lots<T>
where 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.