Skip to main content

Graph

Struct Graph 

Source
pub struct Graph<E> { /* private fields */ }
Expand description

Generic graph structure that can hold any edge type E

Stores edges as an edge list for efficient serialization. Provides adjacency list views for graph algorithms.

Implementations§

Source§

impl<E> Graph<E>

Source

pub fn new() -> Self

Create a new empty graph

Source

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

Add an edge to the graph

Note: Cycle checking must be done by caller if needed (see would_create_cycle method)

Source

pub fn remove_edge(&mut self, source: Uuid, target: Uuid) -> bool
where E: Clone,

Remove an edge between two nodes

Returns true if an edge was removed, false if no matching edge found

Source

pub fn remove_node(&mut self, node_id: Uuid)

Remove all edges involving a node (for deletion cascades)

Source

pub fn archive_node(&mut self, node_id: Uuid)

Archive all edges involving a node (for archive cascades)

Source

pub fn unarchive_node(&mut self, node_id: Uuid)

Unarchive all edges involving a node (for unarchive cascades)

Source

pub fn outgoing(&self, node_id: Uuid) -> Vec<&Edge<E>>

Get all outgoing edges from a node (where node is source)

Source

pub fn incoming(&self, node_id: Uuid) -> Vec<&Edge<E>>

Get all incoming edges to a node (where node is target)

Source

pub fn outgoing_active(&self, node_id: Uuid) -> Vec<&Edge<E>>

Get all active outgoing edges from a node

Source

pub fn incoming_active(&self, node_id: Uuid) -> Vec<&Edge<E>>

Get all active incoming edges to a node

Source

pub fn neighbors(&self, node_id: Uuid) -> Vec<Uuid>
where E: Clone,

Get all neighbor node IDs (connected nodes, handling bidirectional edges)

Source

pub fn neighbors_active(&self, node_id: Uuid) -> Vec<Uuid>
where E: Clone,

Get all active neighbor node IDs

Source

pub fn adjacency_list(&self) -> HashMap<Uuid, Vec<Uuid>>
where E: Clone,

Build an adjacency list view of the graph (for algorithms) Only includes active edges

Source

pub fn edges(&self) -> &[Edge<E>]

Get all edges (for serialization/inspection)

Source

pub fn active_edges(&self) -> Vec<&Edge<E>>

Get all active edges

Source

pub fn has_edge(&self, source: Uuid, target: Uuid) -> bool
where E: Clone,

Check if an edge exists between two nodes

Source

pub fn would_create_cycle(&self, source: Uuid, target: Uuid) -> bool
where E: Clone,

Check if adding an edge would create a cycle Only checks active edges

Source

pub fn has_cycle(&self) -> bool
where E: Clone,

Check if the graph contains any cycles Only checks active edges

Source

pub fn reachable_from(&self, start: Uuid) -> HashSet<Uuid>
where E: Clone,

Get all nodes reachable from a given node Only considers active edges

Source

pub fn edge_count(&self) -> usize

Get the count of edges (total, including archived)

Source

pub fn active_edge_count(&self) -> usize

Get the count of active edges

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Graph<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<E: Debug> Debug for Graph<E>

Source§

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

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

impl<E> Default for Graph<E>

Source§

fn default() -> Self

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

impl<'de, E> Deserialize<'de> for Graph<E>
where E: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<E> Serialize for Graph<E>
where E: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Graph<E>

§

impl<E> RefUnwindSafe for Graph<E>
where E: RefUnwindSafe,

§

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

§

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

§

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

§

impl<E> UnwindSafe for Graph<E>
where 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,