pub struct Graph<'a> { /* private fields */ }Expand description
The entity graph of a parsed file, with forward and back references.
Nodes are positions in Exchange::instances: node n is
exchange.instances()[n]. Each index lists a neighbour once, in
ascending node order, however many times the reference is repeated.
The back index is load-bearing, not an optimisation: a product’s
shape, colours and placement all point at the product, so most
questions about a product are answered by
referenced_by. See docs/ARCHITECTURE.md.
Implementations§
Source§impl<'a> Graph<'a>
impl<'a> Graph<'a>
Sourcepub fn new(exchange: Exchange<'a>) -> Result<Self>
pub fn new(exchange: Exchange<'a>) -> Result<Self>
Builds both reference indices, failing on a dangling reference.
Use this for anything that transforms or extracts: a dangling reference means the file is already missing data, and every graph operation on it would silently produce a wrong answer.
§Errors
Returns Error::UnresolvedReference for the first reference, in
file order, to an instance that is not defined.
Sourcepub fn build(exchange: Exchange<'a>) -> Self
pub fn build(exchange: Exchange<'a>) -> Self
Builds both reference indices, recording dangling references instead of failing.
Use this where a partial answer is still useful, such as reporting
every problem in a file. Dangling references are left out of both
indices and listed by unresolved.
Sourcepub fn references(&self, node: usize) -> &[usize]
pub fn references(&self, node: usize) -> &[usize]
Sourcepub fn referenced_by(&self, node: usize) -> &[usize]
pub fn referenced_by(&self, node: usize) -> &[usize]
Sourcepub fn unresolved(&self) -> &[(usize, u64)]
pub fn unresolved(&self) -> &[(usize, u64)]
References to undefined instances, as (node, missing #id) in file
order. Always empty for a graph from new.