pub struct SerializableGraph {
pub nodes: HashMap<usize, String>,
pub edges: Vec<(usize, usize, Option<String>)>,
pub directed: bool,
pub name: Option<String>,
}Expand description
A simple graph representation for serialization purposes.
Fields§
§nodes: HashMap<usize, String>Nodes: id -> optional label.
edges: Vec<(usize, usize, Option<String>)>Edges: (from, to) -> optional label.
directed: boolWhether the graph is directed.
name: Option<String>Optional graph name.
Implementations§
Source§impl SerializableGraph
impl SerializableGraph
Sourcepub fn new_directed() -> Self
pub fn new_directed() -> Self
Create a new empty directed graph.
Sourcepub fn new_undirected() -> Self
pub fn new_undirected() -> Self
Create a new empty undirected graph.
Sourcepub fn add_node(&mut self, id: usize, label: impl Into<String>)
pub fn add_node(&mut self, id: usize, label: impl Into<String>)
Add a node with an optional label.
Sourcepub fn add_edge(&mut self, from: usize, to: usize, label: Option<String>)
pub fn add_edge(&mut self, from: usize, to: usize, label: Option<String>)
Add an edge between two nodes with an optional label.
Sourcepub fn to_adjacency_list(&self) -> String
pub fn to_adjacency_list(&self) -> String
Serialize to adjacency list format.
Each line: <node_id>: <neighbor1> <neighbor2> ...
Sourcepub fn to_edge_list(&self) -> String
pub fn to_edge_list(&self) -> String
Serialize to edge list format.
Each line: <from> <to> or <from> <to> <label>.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Trait Implementations§
Source§impl Clone for SerializableGraph
impl Clone for SerializableGraph
Source§fn clone(&self) -> SerializableGraph
fn clone(&self) -> SerializableGraph
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SerializableGraph
impl RefUnwindSafe for SerializableGraph
impl Send for SerializableGraph
impl Sync for SerializableGraph
impl Unpin for SerializableGraph
impl UnsafeUnpin for SerializableGraph
impl UnwindSafe for SerializableGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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