Skip to main content

NodeNameNetwork

Struct NodeNameNetwork 

Source
pub struct NodeNameNetwork<NodeName>
where NodeName: Clone + Hash + Eq + Send + Sync + Debug,
{ /* private fields */ }
Expand description

Node Name Network - Pure graph structure for node connections.

Represents the topology of a network without any data attached to nodes or edges. This is useful for graph algorithms that only need connectivity information.

§Type Parameters

  • NodeName: Node name type (must be Clone, Hash, Eq, Send, Sync, Debug)

Implementations§

Source§

impl<NodeName> NodeNameNetwork<NodeName>
where NodeName: Clone + Hash + Eq + Send + Sync + Debug,

Source

pub fn new() -> Self

Create a new empty NodeNameNetwork.

Source

pub fn with_capacity(nodes: usize, edges: usize) -> Self

Create a new NodeNameNetwork with initial capacity.

Source

pub fn add_node(&mut self, node_name: NodeName) -> Result<NodeIndex, String>

Add a node to the network.

Returns an error if the node already exists.

Source

pub fn has_node(&self, node_name: &NodeName) -> bool

Check if a node exists.

Source

pub fn add_edge( &mut self, n1: &NodeName, n2: &NodeName, ) -> Result<EdgeIndex, String>

Add an edge between two nodes.

Returns an error if either node doesn’t exist.

Source

pub fn node_index(&self, node_name: &NodeName) -> Option<NodeIndex>

Get the NodeIndex for a node name.

Source

pub fn node_name(&self, node: NodeIndex) -> Option<&NodeName>

Get the node name for a NodeIndex.

Source

pub fn rename_node( &mut self, old_name: &NodeName, new_name: NodeName, ) -> Result<(), String>

Rename an existing node.

Source

pub fn node_names(&self) -> Vec<&NodeName>

Get all node names.

Source

pub fn node_count(&self) -> usize

Get the number of nodes.

Source

pub fn edge_count(&self) -> usize

Get the number of edges.

Source

pub fn graph(&self) -> &StableGraph<(), (), Undirected>

Get a reference to the internal graph.

Source

pub fn graph_mut(&mut self) -> &mut StableGraph<(), (), Undirected>

Get a mutable reference to the internal graph.

Warning: Directly modifying the internal graph can break the node-name-to-index mapping.

Source

pub fn post_order_dfs(&self, root: &NodeName) -> Option<Vec<NodeName>>

Perform a post-order DFS traversal starting from the given root node.

Returns node names in post-order (children before parents, leaves first).

§Arguments
  • root - The node name to start traversal from
§Returns

Some(Vec<NodeName>) with nodes in post-order, or None if root doesn’t exist.

Source

pub fn post_order_dfs_by_index(&self, root: NodeIndex) -> Vec<NodeIndex>

Perform a post-order DFS traversal starting from the given root NodeIndex.

Returns NodeIndex in post-order (children before parents, leaves first).

Source

pub fn euler_tour_edges( &self, root: &NodeName, ) -> Option<Vec<(NodeIndex, NodeIndex)>>

Perform an Euler tour traversal starting from the given root node.

Delegates to NamedGraph::euler_tour_edges.

Source

pub fn euler_tour_edges_by_index( &self, root: NodeIndex, ) -> Vec<(NodeIndex, NodeIndex)>

Perform an Euler tour traversal starting from the given root NodeIndex.

Delegates to NamedGraph::euler_tour_edges_by_index.

Source

pub fn euler_tour_vertices(&self, root: &NodeName) -> Option<Vec<NodeIndex>>

Perform an Euler tour traversal and return the vertex sequence.

Delegates to NamedGraph::euler_tour_vertices.

Source

pub fn euler_tour_vertices_by_index(&self, root: NodeIndex) -> Vec<NodeIndex>

Perform an Euler tour traversal and return the vertex sequence by NodeIndex.

Delegates to NamedGraph::euler_tour_vertices_by_index.

Source

pub fn path_between( &self, from: NodeIndex, to: NodeIndex, ) -> Option<Vec<NodeIndex>>

Find the shortest path between two nodes using A* algorithm.

Since this is an unweighted graph, we use unit edge weights.

§Returns

Some(Vec<NodeIndex>) containing the path from from to to (inclusive), or None if no path exists.

Source

pub fn is_connected_subset(&self, nodes: &HashSet<NodeIndex>) -> bool

Check if a subset of nodes forms a connected subgraph.

Uses DFS to verify that all nodes in the subset are reachable from each other within the induced subgraph.

§Returns

true if the subset is connected (or empty), false otherwise.

Source

pub fn steiner_tree_nodes( &self, terminals: &HashSet<NodeIndex>, ) -> HashSet<NodeIndex>

Compute the Steiner tree nodes spanning a set of terminal nodes.

For tree graphs, the Steiner tree is the union of the unique paths from one terminal to every other terminal.

§Arguments
  • terminals - Terminal node indices to span
§Returns

The set of nodes in the minimal connected subtree spanning terminals.

§Examples
use std::collections::HashSet;
use tensor4all_treetn::NodeNameNetwork;

let mut net: NodeNameNetwork<String> = NodeNameNetwork::new();
let a = net.add_node("A".to_string()).unwrap();
let b = net.add_node("B".to_string()).unwrap();
let c = net.add_node("C".to_string()).unwrap();
net.add_edge(&"A".to_string(), &"B".to_string()).unwrap();
net.add_edge(&"B".to_string(), &"C".to_string()).unwrap();

let steiner = net.steiner_tree_nodes(&[a, c].into_iter().collect::<HashSet<_>>());
assert_eq!(steiner, [a, b, c].into_iter().collect());
Source

pub fn edges_to_canonicalize( &self, current_region: Option<&HashSet<NodeIndex>>, target: NodeIndex, ) -> CanonicalizeEdges

Compute edges to canonicalize from current state to target.

§Arguments
  • current_region - Current ortho region (None = not canonicalized)
  • target - Target node for the orthogonality center
§Returns

Ordered CanonicalizeEdges to process for canonicalization.

Source

pub fn edges_to_canonicalize_by_names( &self, target: &NodeName, ) -> Option<Vec<(NodeName, NodeName)>>

Compute edges to canonicalize from leaves to target, returning node names.

This is similar to edges_to_canonicalize(None, target) but returns (from_name, to_name) pairs instead of (NodeIndex, NodeIndex).

Useful for operations that work with two networks that have the same topology but different NodeIndex values (e.g., contract_zipup).

§Arguments
  • target - Target node name for the orthogonality center
§Returns

None if target node doesn’t exist, otherwise a vector of (from, to) pairs where from is the node being processed and to is its parent (towards target).

Source

pub fn edges_to_canonicalize_to_region( &self, target_region: &HashSet<NodeIndex>, ) -> CanonicalizeEdges

Compute edges to canonicalize from leaves towards a connected region (multiple centers).

Given a set of target nodes forming a connected region, this function returns all edges (src, dst) where:

  • src is a node outside the target region
  • dst is the next node towards the target region

The edges are ordered so that nodes farther from the target region are processed first (children before parents), which is the correct order for canonicalization.

§Arguments
  • target_region - Set of NodeIndex that forms the canonical center region (must be non-empty and connected)
§Returns

CanonicalizeEdges with all edges pointing towards the target region. Returns empty edges if target_region is empty.

§Panics

Does not panic, but if target_region is disconnected, behavior is undefined (may return partial results).

Source

pub fn edges_to_canonicalize_to_region_by_names( &self, target_region: &HashSet<NodeName>, ) -> Option<Vec<(NodeName, NodeName)>>

Compute edges to canonicalize towards a region, returning node names.

This is similar to edges_to_canonicalize_to_region but takes and returns node names instead of NodeIndex.

§Arguments
  • target_region - Set of node names that forms the canonical center region
§Returns

None if any target node doesn’t exist, otherwise Some(Vec<(from, to)>) where edges point towards the target region.

Source

pub fn same_topology(&self, other: &Self) -> bool

Check if two networks have the same topology (same nodes and edges).

Trait Implementations§

Source§

impl<NodeName> Clone for NodeNameNetwork<NodeName>
where NodeName: Clone + Hash + Eq + Send + Sync + Debug + Clone,

Source§

fn clone(&self) -> NodeNameNetwork<NodeName>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<NodeName> Debug for NodeNameNetwork<NodeName>
where NodeName: Clone + Hash + Eq + Send + Sync + Debug + Debug,

Source§

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

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

impl<NodeName> Default for NodeNameNetwork<NodeName>
where NodeName: Clone + Hash + Eq + Send + Sync + Debug,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<NodeName> Freeze for NodeNameNetwork<NodeName>

§

impl<NodeName> RefUnwindSafe for NodeNameNetwork<NodeName>
where NodeName: RefUnwindSafe,

§

impl<NodeName> Send for NodeNameNetwork<NodeName>

§

impl<NodeName> Sync for NodeNameNetwork<NodeName>

§

impl<NodeName> Unpin for NodeNameNetwork<NodeName>
where NodeName: Unpin,

§

impl<NodeName> UnsafeUnpin for NodeNameNetwork<NodeName>

§

impl<NodeName> UnwindSafe for NodeNameNetwork<NodeName>
where NodeName: UnwindSafe,

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
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T