Struct alot::ordered::OrderedLots

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

A collection of T values that maintains the order of elements.

This collection can be accessed by index (usize) or the LotId it is assigned upon insertion or pushing.

This collection has Vec-like performance except when removing elements by LotId, which is an O(n) operation.

Implementations§

source§

impl<T> OrderedLots<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 end of the collection, returning the value’s unique LotId.

source

pub fn pop(&mut self) -> Option<T>

Removes the last element of the collection, if one is present.

source

pub fn pop_entry(&mut self) -> Option<(LotId, T)>

Removes the last element of the collection, if one is present.

source

pub fn insert(&mut self, offset: usize, value: T) -> LotId

Inserts value at offset inside of the collection.

Panics

This funciton panics if offset is greater than the length of the collection.

source

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

Removes the value with the associated LotId, if found.

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

source

pub fn remove_by_index(&mut self, index: usize) -> Option<(LotId, T)>

Removes the value at index, returning the LotId and value if found.

source

pub fn sort(&mut self)
where T: Ord,

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort() for more information.

source

pub fn sort_by<F: Fn(&T, &T) -> Ordering>(&mut self, comparison: F)

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort_by() for more information.

source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort_by_key() for more information.

source

pub fn sort_by_cached_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort_by_cached_key() for more information.

source

pub fn sort_unstable(&mut self)
where T: Ord,

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort_unstable() for more information.

source

pub fn sort_unstable_by<F: Fn(&T, &T) -> Ordering>(&mut self, comparison: F)

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort_unstable_by() for more information.

source

pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Orders the elements in this collection leveraging the standard library’s sorting implementation. See slice::sort_unstable_by_key() for more information.

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 get_by_index(&self, index: usize) -> Option<&T>

Looks up a value by index. If index is greater than or equal to the collections length, None will be returned.

source

pub fn get_mut_by_index(&mut self, index: usize) -> Option<&mut T>

Looks up a mutable reference to a value by index. If index is greater than or equal to the collections length, None will be returned.

source

pub fn index_of_id(&self, id: LotId) -> Option<usize>

Returns the index of id, or None if the id is not contained in this collection.

source

pub fn id(&self, index: usize) -> Option<LotId>

Returns the id of the entry at index, or None if index is outside of the bounds of this collection.

source

pub fn key(&self, index: usize) -> Option<LotId>

Returns the LotId associated with a given index. Returns None if index is greater than or equal to the collections length.

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 entries(&self) -> EntryIter<'_, T>

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

source

pub fn first(&self) -> Option<&T>

Returns the first entry in this collection, or None if the collection is empty.

source

pub fn first_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the first entry in this collection, or None if the collection is empty.

source

pub fn last(&self) -> Option<&T>

Returns the last entry in this collection, or None if the collection is empty.

source

pub fn last_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the last entry in this collection, or None if the collection is empty.

source

pub fn swap(&mut self, a: usize, b: usize)

Swaps the elements at index a and b.

Internally, this only moves a LotId. The underlying data does not change, and its each value’s associated LotId does not change.

Trait Implementations§

source§

impl<T: Clone> Clone for OrderedLots<T>

source§

fn clone(&self) -> OrderedLots<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 OrderedLots<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 OrderedLots<T>

source§

fn default() -> Self

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

impl<T> FromIterator<T> for OrderedLots<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 OrderedLots<T>

§

type Output = T

The returned type after indexing.
source§

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

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

impl<T> Index<usize> for OrderedLots<T>

§

type Output = T

The returned type after indexing.
source§

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

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

impl<T> IndexMut<LotId> for OrderedLots<T>

source§

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

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

impl<T> IndexMut<usize> for OrderedLots<T>

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

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

impl<'a, T> IntoIterator for &'a OrderedLots<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<T> IntoIterator for OrderedLots<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<'a, T> PartialEq<&'a [T]> for OrderedLots<T>
where T: PartialEq,

source§

fn eq(&self, other: &&'a [T]) -> 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<'a, T, const N: usize> PartialEq<&'a [T; N]> for OrderedLots<T>
where T: PartialEq,

source§

fn eq(&self, other: &&'a [T; N]) -> 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> PartialEq<[T]> for OrderedLots<T>
where T: PartialEq,

source§

fn eq(&self, other: &[T]) -> 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, const N: usize> PartialEq<[T; N]> for OrderedLots<T>
where T: PartialEq,

source§

fn eq(&self, other: &[T; N]) -> 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> PartialEq for OrderedLots<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 OrderedLots<T>
where T: Eq,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for OrderedLots<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.