pub struct Index<'a> { /* private fields */ }Expand description
What is in a file, without what it says.
Borrows the source bytes and stores four parallel columns plus a table of
distinct type names. At roughly 24 bytes per entity this is two orders of
magnitude smaller than the decoded Model.
Use Index::entity to decode one record, or Index::materialize_closure
to build a real Model from a chosen subset.
Implementations§
Source§impl<'a> Index<'a>
impl<'a> Index<'a>
Sourcepub fn scan(source: &'a [u8]) -> Self
pub fn scan(source: &'a [u8]) -> Self
Scans source for record boundaries. Does not decode attributes.
Sourcepub fn type_of(&self, id: EntityId) -> Option<&str>
pub fn type_of(&self, id: EntityId) -> Option<&str>
Upper-cased type name of id, without decoding it.
Sourcepub fn count_by_type(&self) -> BTreeMap<&str, usize>
pub fn count_by_type(&self) -> BTreeMap<&str, usize>
How many records of each type. The census a viewer opens with.
Sourcepub fn ids_of_type(&self, name: &str) -> Vec<EntityId>
pub fn ids_of_type(&self, name: &str) -> Vec<EntityId>
Ids of every record whose type matches name, case-insensitively.
Sourcepub fn entity(&self, id: EntityId) -> Option<Entity>
pub fn entity(&self, id: EntityId) -> Option<Entity>
Decodes one record into an Entity.
The record is wrapped in a minimal synthetic file and handed to the real parser, so a lazily decoded entity cannot drift from its eager counterpart: there is only one decoder.
Sourcepub fn materialize(&self, wanted: &[EntityId]) -> Model
pub fn materialize(&self, wanted: &[EntityId]) -> Model
Builds a Model from exactly wanted, and nothing else.
§Dangling references
The result is a real Model but not a self-contained one: an entity
that referenced #7 still says Ref(7) even when #7 was not
requested. Traversal will not resolve it. Use
Index::materialize_closure unless you specifically want the raw
subset and will handle missing targets yourself.
Sourcepub fn materialize_closure(&self, wanted: &[EntityId]) -> Model
pub fn materialize_closure(&self, wanted: &[EntityId]) -> Model
Builds a Model containing wanted and everything they reach.
Follows references transitively, so the result has no dangling
Ref. This is the constructor to reach for: it is what makes a
subset independently usable.