pub struct DocIndex {
built_from: Option<DocStamp>,
pub blocks: HashMap<BlockId, BlockIndex>,
pub routes: HashMap<RouteId, RouteIndex>,
pub routes_by_endpoint: HashMap<PinId, HashSet<RouteId>>,
}Expand description
The derived index over the whole document — never authoritative. A child whose owner has been deleted is indexed nowhere (its owner has no entry).
Owned, and stamp-gated through Self::view: the third instance of
the pattern the app already runs for its spatial tree (CachedIndex)
and its route-accent propagation (PinAccents) — kept across frames,
rebuilt from the document value alone, so no mutation site has to
remember to invalidate it.
Fields§
§built_from: Option<DocStamp>None until the first build; the empty index describes no
document, not the empty one.
blocks: HashMap<BlockId, BlockIndex>Every block’s scope, plus the document root under Id::NULL —
whose children are the top-level blocks and whose other sets hold
the entities owned by the root directly. A row here is a scope,
which the root is and a block also is; Self::holds_block is the
other question.
routes: HashMap<RouteId, RouteIndex>§routes_by_endpoint: HashMap<PinId, HashSet<RouteId>>Every route, keyed by both endpoint pins — the adjacency the delete cascade and pin drags ask for.
Implementations§
Source§impl DocIndex
impl DocIndex
Sourcepub fn of(doc: &Document) -> Self
pub fn of(doc: &Document) -> Self
One linear pass over every kind. The ad-hoc path, for a caller
with nowhere to keep an index between document values; a caller
that has somewhere keeps one and calls Self::view.
Sourcepub fn scope(&self, id: BlockId) -> Option<&BlockIndex>
pub fn scope(&self, id: BlockId) -> Option<&BlockIndex>
The contents of scope: a block’s interior, or the document root
(Id::NULL). Every block has a row and so does the root, so a
None here means the scope is gone, never that it is the root.
Sourcepub fn holds_block(&self, id: BlockId) -> bool
pub fn holds_block(&self, id: BlockId) -> bool
Whether id names a block the document holds. The root’s row is a
scope without an entity behind it — nothing can delete, move, or
rename it — so it answers false here while still answering
Self::scope.
Sourcepub fn view<'a>(&'a mut self, doc: &'a Document) -> IndexedDocument<'a>
pub fn view<'a>(&'a mut self, doc: &'a Document) -> IndexedDocument<'a>
doc bundled with this index, rebuilt first unless it was already
built from that very document value.
Sourcepub fn view_of<'a>(&'a self, doc: &'a Document) -> Option<IndexedDocument<'a>>
pub fn view_of<'a>(&'a self, doc: &'a Document) -> Option<IndexedDocument<'a>>
The view over the document value this index was built from, and
None for any other — the read-only door, for a caller holding a
document and an index it built together and with no &mut to
rebuild through. Refusing the mismatched pair is the whole point:
it is the same check Self::view makes, minus the repair.