pub struct HdtGraph { /* private fields */ }Expand description
Exact connectivity using deterministic HDT levels and AVL tours.
Preserves the crate::Graph contract, including growing arbitrary u64
vertices. This is an experimental implementation, not a production latency
guarantee. Compact BFS remains the default engine.
Stable interface, experimental engine. This type, its methods and its trait implementations are stable for 1.x: they are removed or changed incompatibly only after a deprecation and in a major release. The experimental qualification covers performance, maturity and usage recommendation only: the cost bounds below describe the current implementation and are not a compatibility promise (compatibility policy).
Queries cost O(log V) algorithmically on the base forest, with expected O(1) hash map ID lookup, and allocate no scratch. Across a history with at most N registered vertices, edge updates have O(log² N) amortized cost; one cut may still inspect many edges. Logical storage is O(E + V log V): each level holds one spanning-forest copy of its tree edges and records only for vertices currently in that forest or holding exact-level incidences. Records that become isolated are released for reuse and emptied incidence sets free their nodes, so storage follows the live level structure rather than the history of promotions; arena and vector capacities, and released record slots, still retain their peaks (vector capacity is at most twice the peak length). Vertex insertion costs O(1) amortized for base forest, including ID indexing. Upper levels store only vertices touched by promotions; creating these records is charged to promotions. Vector reallocations can still cause linear spikes. Neither graph state nor query answers are protected by internal locks.
Implementations§
Source§impl HdtGraph
impl HdtGraph
Sourcepub fn add_node(&mut self, node: NodeId) -> bool
pub fn add_node(&mut self, node: NodeId) -> bool
Registers an isolated vertex, returning false if already present.
Registers only in the base forest. Growing the universe relaxes upper level size bounds; implicit isolated vertices need no upper records.
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 edge at level zero, creating absent endpoints.
Returns false for a duplicate, including reversed endpoints.
§Errors
Rejects self-loops before creating any vertex.
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 edge, retaining all vertices; absent edges return false.
Every repair completes before returning. A single expensive cut is still possible: the update bound is amortized over edge lifetimes and promotions.
§Errors
Rejects self-loops without changing state.
Sourcepub fn connected(
&self,
source: NodeId,
target: NodeId,
) -> Result<bool, GraphError>
pub fn connected( &self, source: NodeId, target: NodeId, ) -> Result<bool, GraphError>
Answers exact connectivity in O(log V) algorithmic tree root time on level 0, with expected O(1) hash map ID lookup, without allocation or mutation.
A known vertex connects to itself. Unknown source is reported first.
§Errors
Returns GraphError::UnknownNode for an unregistered endpoint.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of registered vertices in O(1).
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of graph edges in O(1).
Sourcepub fn stats(&self) -> HdtStats
pub fn stats(&self) -> HdtStats
Returns the diagnostic counters accumulated since creation or the last
Self::reset_stats, in O(1) without changing any state.
HdtStats lists which properties of the values are guaranteed.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Sets every diagnostic counter to zero without altering graph state.
Sourcepub fn storage_stats(&self) -> HdtStorageStats
pub fn storage_stats(&self) -> HdtStorageStats
Collects structural storage accounting without changing graph state.
The values are computed at the call and describe the graph at that
moment; the returned snapshot does not follow later mutations. Calling
it changes neither the graph nor Self::stats. Takes O(V log V + E)
time in the worst case and allocates the returned per-level snapshot.
Call outside measured operations. Vector capacities exclude allocator
overhead; mapping payload excludes hash table overhead and spare slots.
This is deliberately not a total heap or RSS estimate.
crate::HdtStorageStats and crate::HdtLevelStorage list which
properties of the values are guaranteed and which are
implementation-dependent.