pub struct ReferenceGraph { /* private fields */ }Expand description
An undirected simple graph with exact connectivity queries.
Every stored edge appears in both endpoints’ adjacency sets. Sets exclude self-loops and duplicate edges; every endpoint has a vertex entry. Deleting an edge preserves its vertices. Storage is O(V + E), where V and E are the current vertex and undirected edge counts.
Internal test oracle; no stability promise. It exists for differential
tests and benchmarks and may change or disappear in any release; see
docs/stability.md. Use Graph or
ConnectivityGraph instead.
Implementations§
Source§impl ReferenceGraph
impl ReferenceGraph
Sourcepub fn add_node(&mut self, node: NodeId) -> bool
pub fn add_node(&mut self, node: NodeId) -> bool
Adds an isolated vertex, returning true only if it was absent.
An existing vertex and its edges are unchanged. Worst-case time: O(log V).
Sourcepub fn link(
&mut self,
source: NodeId,
target: NodeId,
) -> Result<bool, GraphError>
pub fn link( &mut self, source: NodeId, target: NodeId, ) -> Result<bool, GraphError>
Inserts an undirected edge, creating absent endpoints.
Returns true only when the edge is new. Reversed endpoints identify
the same edge. Worst-case time: O(log V).
§Errors
Returns GraphError::SelfLoop for equal endpoints, without changing the graph.
Sourcepub fn cut(
&mut self,
source: NodeId,
target: NodeId,
) -> Result<bool, GraphError>
pub fn cut( &mut self, source: NodeId, target: NodeId, ) -> Result<bool, GraphError>
Removes an undirected edge while preserving both vertices.
Returns false if the edge or either endpoint is absent. Worst-case
time: O(log V).
§Errors
Returns GraphError::SelfLoop for equal endpoints, without changing the graph.
Sourcepub fn connected(
&self,
source: NodeId,
target: NodeId,
) -> Result<bool, GraphError>
pub fn connected( &self, source: NodeId, target: NodeId, ) -> Result<bool, GraphError>
Reports whether a path exists between two existing vertices.
An existing vertex connects to itself by the empty path. Worst-case time is O((V + E) log V); scratch memory is O(V). These are worst-case bounds, not amortized bounds. Traversal stops early when the target is found.
§Errors
Returns GraphError::UnknownNode for an absent endpoint, checking
source before target.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of vertices, including isolated ones, in O(1) time.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of undirected edges in O(1) time.