Skip to main content

Keyed

Struct Keyed 

Source
pub struct Keyed<T> { /* private fields */ }
Expand description

A keyed collection that keeps its own key→index map, so an element read is O(1) rather than a scan, and no caller can forget to maintain the map, because the collection does it.

Implementations§

Source§

impl<T> Keyed<T>
where T: Identified,

Source

pub fn new(items: Vec<T>) -> Keyed<T>

Source

pub fn reindex(&mut self)

Rebuild the map. O(n); integer keys pay no interner cost here, wide keys pay one read-locked lookup per row.

Source

pub fn reindex_if_stale(&mut self)

Rebuild only if raw access may have invalidated the map: what Store::restructure calls, so appending a row stays O(1) instead of rebuilding the whole index per insert.

Source

pub fn get(&self, key: u64) -> Option<&T>

Source

pub fn get_mut(&mut self, key: u64) -> Option<&mut T>

Source

pub fn keys(&self) -> Vec<u64>

Source

pub fn items(&self) -> &[T]

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn next_key(&self) -> u64

The next free integer key: one past the largest in use (1 for an empty collection), or the lowest unused key from 1 once that would reach the top bit integer keys reserve (see AsKey). Interned keys (Uuid, Str, Pair) are not counted.

Source

pub fn push(&mut self, item: T)

Source

pub fn remove(&mut self, key: u64) -> Option<T>

Source

pub fn move_item(&mut self, from: usize, to: usize)

Source

pub fn clear(&mut self)

Remove every row. What a reload wants before pushing the new set, in one call rather than a Keyed::remove (and a reindex) per key.

Source

pub fn items_mut(&mut self) -> &mut Vec<T>

The raw list, for a structural edit inside Store::restructure that the helpers above do not cover. Taking it marks the key map stale, so the store rebuilds it after the caller’s closure returns; the helpers above stay index-correct on their own and pay nothing for this.

Trait Implementations§

Source§

impl<T> Default for Keyed<T>
where T: Identified,

Source§

fn default() -> Keyed<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for Keyed<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for Keyed<T>

§

impl<T> UnwindSafe for Keyed<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
§

impl<T> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.