Skip to main content

ForestGraph

Struct ForestGraph 

Source
pub struct ForestGraph { /* private fields */ }
Expand description

Exact connectivity with deterministic Euler-tour trees.

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).

Maintains a spanning forest: each graph component has exactly one tree. Non-tree edges are stored at both endpoints. Removing a forest edge scans non-tree edges incident to its smaller side; a crossing edge reconnects the trees, or exhaustion proves a real split. This is not HDT: repeated scans have no polylogarithmic amortized bound. The default crate::Graph is unchanged.

AVL root queries cost O(log V) algorithmically, with expected O(1) ID hash map translation. Link costs O(log V + log E) amortized including arena growth. A tree cut costs (amortized for free-list growth) O(log V + log E + min(s, (k+1) log V) + c log V), where s is the smaller side size, k the yielded candidate-bearing vertices, and c the examined non-tree incidences. Empty candidate sets require no enumeration. Non-tree cuts cost O(log V + log E). A single token-arena or free-list growth can add O(V) time. Logical storage is O(V + E); allocated arenas retain O(V) high-water capacity, removed tree-edge slots are reused and an emptied non-tree incidence set frees its storage. Queries allocate no scratch, cache no answers and use no internal locks.

Implementations§

Source§

impl ForestGraph

Source

pub fn new() -> Self

Creates an empty graph in O(1) time.

Source

pub fn add_node(&mut self, node: NodeId) -> bool

Registers an isolated vertex; returns false for an existing ID.

O(1) amortized; arena/vector growth can take O(V) in one call.

Inserts a simple undirected edge, registering absent endpoints.

Returns false for an existing edge, including reversed endpoints.

§Errors

Rejects self-loops before registering either endpoint.

Source

pub fn cut( &mut self, source: NodeId, target: NodeId, ) -> Result<bool, GraphError>

Removes an edge while retaining both vertices; absent edges return false.

Tree cuts synchronously complete replacement search before returning.

§Errors

Rejects self-loops without changing graph state.

Source

pub fn connected( &self, source: NodeId, target: NodeId, ) -> Result<bool, GraphError>

Answers exact connectivity in O(log V) algorithmic tree root time, plus expected O(1) hash map lookup for node IDs, without allocation.

Existing vertices connect to themselves, including isolated vertices.

§Errors

Reports an absent source before an absent target.

Source

pub fn node_count(&self) -> usize

Returns the number of registered vertices in O(1) time.

Source

pub fn edge_count(&self) -> usize

Returns the number of undirected graph edges in O(1) time.

Source

pub fn stats(&self) -> ForestStats

Returns the replacement-search counters accumulated since creation or the last Self::reset_stats, in O(1) time without changing any state.

ForestStats lists which properties of the values are guaranteed.

Source

pub fn reset_stats(&mut self)

Sets every diagnostic counter to zero, preserving all graph state.

Trait Implementations§

Source§

impl Debug for ForestGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ForestGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for ForestGraph

§

impl Freeze for ForestGraph

§

impl Move for ForestGraph

§

impl RefUnwindSafe for ForestGraph

§

impl Send for ForestGraph
where RawTable<(u64, usize)>: Send, RawVecInner: Send, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Send, BoxRaw<(usize, SetValZST)>: Send, RawTable<((usize, usize), Option<(usize, usize)>)>: Send, NonZero<usize>: Send,

§

impl Sync for ForestGraph
where RawTable<(u64, usize)>: Sync, RawVecInner: Sync, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Sync, BoxRaw<(usize, SetValZST)>: Sync, RawTable<((usize, usize), Option<(usize, usize)>)>: Sync, NonZero<usize>: Sync,

§

impl Unpin for ForestGraph
where *const u8 is !null: Unpin, *const LeafNode<usize, SetValZST> is !null: Unpin, Box<(usize, SetValZST)>: Unpin, NonZero<usize>: Unpin,

§

impl UnsafeUnpin for ForestGraph

§

impl UnwindSafe for ForestGraph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.