Graph

Struct Graph 

Source
pub struct Graph<N = (), E = ()> { /* private fields */ }
Expand description

Graph container for nodes and edges

Implementations§

Source§

impl<N, E> Graph<N, E>

Source

pub fn apply_node_drag( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, ) -> Result<()>

Apply drag operation to selected nodes

Source

pub fn apply_node_drag_with_bounds( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, bounds: Option<Rect>, ) -> Result<()>

Apply drag operation with bounds constraint

Source

pub fn apply_node_drag_with_snap( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, grid_size: f64, ) -> Result<()>

Apply drag operation with grid snapping

Source

pub fn apply_node_drag_with_constraint<F>( &mut self, selected_nodes: &HashSet<NodeId>, delta: Position, constraint: F, ) -> Result<()>
where F: Fn(Position) -> Position,

Apply drag operation with custom constraint function

Source

pub fn create_drag_operation( &self, selected_nodes: &HashSet<NodeId>, delta: Position, ) -> Result<DragOperation>

Create a drag operation for undo/redo support

Source§

impl<N, E> Graph<N, E>
where N: Clone, E: Clone,

Source

pub fn has_cycle(&self) -> bool

Check if the graph contains any cycles using DFS-based cycle detection

Uses Depth-First Search with recursion stack tracking to detect back edges. Time complexity: O(V + E), Space complexity: O(V)

Source

pub fn creates_cycle(&self, source: &NodeId, target: &NodeId) -> bool

Check if adding an edge from source to target would create a cycle

This is useful for preventing cycles during interactive edge creation. Time complexity: O(V + E), Space complexity: O(V)

Source

pub fn find_cycle(&self) -> Option<Vec<NodeId>>

Find a cycle in the graph, returning the cycle path if found

Returns the first cycle found, or None if the graph is acyclic. The returned path represents the nodes in the cycle. Time complexity: O(V + E), Space complexity: O(V)

Source

pub fn topological_sort(&self) -> Result<Vec<NodeId>>

Perform topological sort on the graph using Kahn’s algorithm

Returns a valid topological ordering of nodes, or Err if the graph contains cycles. A topological sort is a linear ordering where for every directed edge (u, v), vertex u comes before v in the ordering. Time complexity: O(V + E), Space complexity: O(V)

Source§

impl<N, E> Graph<N, E>

Source

pub fn add_handle_edge(&mut self, edge: Edge<E>) -> Result<()>

Add an edge with handle validation

Source

pub fn get_handle_connections( &self, node_id: &NodeId, handle_id: &HandleId, ) -> Vec<&Edge<E>>

Get all edges connected to a specific handle

This method provides accurate connection counting by examining all edges in the graph that reference the specified handle.

Source

pub fn can_handle_accept_connection( &self, node_id: &NodeId, handle_id: &HandleId, ) -> bool

Check if a handle can accept new connections (respects connection limits)

This method provides accurate connection limit validation by counting current connections and comparing against the handle’s limit.

Source§

impl<N, E> Graph<N, E>

Source

pub fn new() -> Self

Create a new empty graph

Source

pub fn add_node(&mut self, node: Node<N>) -> Result<()>

Add a node to the graph

Source

pub fn remove_node(&mut self, node_id: &NodeId) -> Result<Node<N>>

Remove a node and all connected edges

Source

pub fn get_node(&self, node_id: &NodeId) -> Option<&Node<N>>

Get a reference to a node

Source

pub fn get_node_mut(&mut self, node_id: &NodeId) -> Option<&mut Node<N>>

Get a mutable reference to a node

Source

pub fn add_edge(&mut self, edge: Edge<E>) -> Result<()>

Add an edge to the graph

Source

pub fn remove_edge(&mut self, edge_id: &EdgeId) -> Result<Edge<E>>

Remove an edge

Source

pub fn get_edge(&self, edge_id: &EdgeId) -> Option<&Edge<E>>

Get a reference to an edge

Source

pub fn get_edge_mut(&mut self, edge_id: &EdgeId) -> Option<&mut Edge<E>>

Get a mutable reference to an edge

Source

pub fn nodes(&self) -> impl Iterator<Item = &Node<N>>

Get all nodes

Source

pub fn nodes_mut(&mut self) -> impl Iterator<Item = &mut Node<N>>

Get all nodes mutably

Source

pub fn edges(&self) -> impl Iterator<Item = &Edge<E>>

Get all edges

Source

pub fn edges_mut(&mut self) -> impl Iterator<Item = &mut Edge<E>>

Get all edges mutably

Source

pub fn node_count(&self) -> usize

Get node count

Source

pub fn edge_count(&self) -> usize

Get edge count

Source

pub fn is_empty(&self) -> bool

Check if graph is empty

Source

pub fn clear(&mut self)

Clear all nodes and edges

Source

pub fn get_connected_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>

Get edges connected to a node

Source

pub fn get_incoming_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>

Get incoming edges for a node

Source

pub fn get_outgoing_edges(&self, node_id: &NodeId) -> Vec<&Edge<E>>

Get outgoing edges for a node

Source

pub fn are_connected(&self, source: &NodeId, target: &NodeId) -> bool

Check if two nodes are connected

Source

pub fn node_ids(&self) -> impl Iterator<Item = &NodeId>

Get all node IDs

Source

pub fn edge_ids(&self) -> impl Iterator<Item = &EdgeId>

Get all edge IDs

Source

pub fn bounds(&self) -> Option<Rect>
where N: Clone,

Calculate bounding rectangle of all nodes

Source

pub fn handle_at_position( &self, point: Position, handle_size: f64, ) -> Option<(&NodeId, &Handle)>

Find handle at position in the graph

Source

pub fn get_handles_by_type( &self, handle_type: HandleType, ) -> Vec<(&NodeId, &Handle)>

Get all handles of a specific type in the graph

Source

pub fn create_edge_creator(&self) -> EdgeCreator

Create a new edge creator for this graph

Trait Implementations§

Source§

impl<N: Clone, E: Clone> Clone for Graph<N, E>

Source§

fn clone(&self) -> Graph<N, E>

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<N: Debug, E: Debug> Debug for Graph<N, E>

Source§

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

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

impl<N, E> Default for Graph<N, E>

Source§

fn default() -> Self

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

impl<N: PartialEq, E: PartialEq> PartialEq for Graph<N, E>

Source§

fn eq(&self, other: &Graph<N, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<N, E> StructuralPartialEq for Graph<N, E>

Auto Trait Implementations§

§

impl<N, E> Freeze for Graph<N, E>

§

impl<N, E> RefUnwindSafe for Graph<N, E>

§

impl<N, E> Send for Graph<N, E>
where N: Send, E: Send,

§

impl<N, E> Sync for Graph<N, E>
where N: Sync, E: Sync,

§

impl<N, E> Unpin for Graph<N, E>
where N: Unpin, E: Unpin,

§

impl<N, E> UnwindSafe for Graph<N, E>
where N: UnwindSafe, E: 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
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> 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
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> 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.