pub struct Topology(/* private fields */);Expand description
Topology.
This data type represents the topology of a graph, which allows to find the
outgoing and incoming edges for each node in linear time by using efficient
adjacency lists. Note that our implementation does not support edge weights,
as they’re not necessary for scheduling purposes, and they would only add
unnecessary complexity and overhead. The topology also contains the lazily
computed Distance matrix that allows to find the shortest path between
two nodes in the graph, or determine whether they’re reachable at all.
The graph topology must be considered immutable, as Adjacency lists
can’t be mutated anyway, and represents the conversion of a graph into an
executable form. In order to modify the graph, convert it back into a
builder using the Graph::into_builder method.
The Topology data type is just a wrapper around [TopologyInner] with
an Rc, so it can be shared between the Graph and Traversal
structures without the need for lifetime annotations, which would render
incremental and asynchronous traversals of graphs more complex.
Implementations§
Source§impl Topology
impl Topology
Sourcepub fn new(nodes: usize, edges: &[Edge]) -> Self
pub fn new(nodes: usize, edges: &[Edge]) -> Self
Creates a topology of the given graph.
This method constructs a topology from a graph builder, one of the key
components of an executable Graph. Thus, it’s usually not needed
to create a topology manually, as it’s automatically created when the
graph is built using the [Builder::build] method.
§Examples
use zrx_graph::{Graph, Topology};
// Create graph builder and add nodes
let mut builder = Graph::builder();
let a = builder.add_node("a");
let b = builder.add_node("b");
let c = builder.add_node("c");
// Create edges between nodes
builder.add_edge(a, b)?;
builder.add_edge(b, c)?;
// Create topology
let topology = Topology::new(builder.len(), builder.edges());