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: Identified> Keyed<T>
impl<T: Identified> Keyed<T>
pub fn new(items: Vec<T>) -> Self
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.