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,
impl<T> Keyed<T>where
T: Identified,
pub fn new(items: Vec<T>) -> Keyed<T>
Sourcepub fn reindex(&mut self)
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.
Sourcepub fn reindex_if_stale(&mut self)
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.
pub fn get(&self, key: u64) -> Option<&T>
pub fn get_mut(&mut self, key: u64) -> Option<&mut T>
pub fn keys(&self) -> Vec<u64>
pub fn items(&self) -> &[T]
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn next_key(&self) -> u64
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.
pub fn push(&mut self, item: T)
pub fn remove(&mut self, key: u64) -> Option<T>
pub fn move_item(&mut self, from: usize, to: usize)
Sourcepub fn clear(&mut self)
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.
Sourcepub fn items_mut(&mut self) -> &mut Vec<T>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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