pub struct Graph {
pub guid: String,
pub name: String,
pub vertex_count: i32,
pub edge_count: i32,
vertices: HashMap<String, Vertex>,
edges: HashMap<String, HashMap<String, Edge>>,
}
Fields§
§guid: String
§name: String
§vertex_count: i32
§edge_count: i32
§vertices: HashMap<String, Vertex>
§edges: HashMap<String, HashMap<String, Edge>>
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn add_edge(
&mut self,
u: &str,
v: &str,
attribute: &str,
) -> (String, String)
pub fn add_edge( &mut self, u: &str, v: &str, attribute: &str, ) -> (String, String)
Adds an edge between u and v.
Sourcepub fn number_of_vertices(&self) -> usize
pub fn number_of_vertices(&self) -> usize
Gets the number of vertices in the graph.
Sourcepub fn number_of_edges(&self) -> usize
pub fn number_of_edges(&self) -> usize
Gets the number of edges in the graph.
Sourcepub fn get_vertices(&self) -> Vec<Vertex>
pub fn get_vertices(&self) -> Vec<Vertex>
Gets all vertices in the graph.
Sourcepub fn get_edges(&self) -> Vec<(String, String)>
pub fn get_edges(&self) -> Vec<(String, String)>
Gets all edges in the graph as tuples of vertex names.
Sourcepub fn remove_node(&mut self, key: &str)
pub fn remove_node(&mut self, key: &str)
Removes a node and all its edges from the graph.
Sourcepub fn remove_edge(&mut self, edge: (&str, &str))
pub fn remove_edge(&mut self, edge: (&str, &str))
Removes an edge from the graph.
Sourcepub fn node_attribute(
&mut self,
node: &str,
value: Option<&str>,
) -> Option<String>
pub fn node_attribute( &mut self, node: &str, value: Option<&str>, ) -> Option<String>
Get or set node attribute.
Sourcepub fn to_json_data(&self) -> Result<String, Error>
pub fn to_json_data(&self) -> Result<String, Error>
Serializes the Graph to a JSON string.
Sourcepub fn from_json_data(json_data: &str) -> Result<Self, Error>
pub fn from_json_data(json_data: &str) -> Result<Self, Error>
Deserializes a Graph from a JSON string.
Sourcepub fn to_json(&self, filepath: &str) -> Result<(), Box<dyn Error>>
pub fn to_json(&self, filepath: &str) -> Result<(), Box<dyn Error>>
Serializes the Graph to a JSON file.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Graph
impl<'de> Deserialize<'de> for Graph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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