Graph

Trait Graph 

Source
pub trait Graph {
    // Required methods
    fn empty<I, V>(labels: I) -> Self
       where I: IntoIterator<Item = V>,
             V: AsRef<str>;
    fn complete<I, V>(labels: I) -> Self
       where I: IntoIterator<Item = V>,
             V: AsRef<str>;
    fn vertices(&self) -> Set<usize>;
    fn has_vertex(&self, x: usize) -> bool;
    fn edges(&self) -> Set<(usize, usize)>;
    fn has_edge(&self, x: usize, y: usize) -> bool;
    fn add_edge(&mut self, x: usize, y: usize) -> bool;
    fn del_edge(&mut self, x: usize, y: usize) -> bool;
    fn from_adjacency_matrix(
        labels: Labels,
        adjacency_matrix: Array2<bool>,
    ) -> Self;
    fn to_adjacency_matrix(&self) -> Array2<bool>;
}
Expand description

A trait for graphs.

Required Methods§

Source

fn empty<I, V>(labels: I) -> Self
where I: IntoIterator<Item = V>, V: AsRef<str>,

Creates an empty graph with the given labels.

§Arguments
  • labels - The labels of the vertices in the graph.
§Notes
  • Labels will be sorted in alphabetical order.
§Panics
  • If the labels are not unique.
§Returns

A new graph instance.

Source

fn complete<I, V>(labels: I) -> Self
where I: IntoIterator<Item = V>, V: AsRef<str>,

Creates a complete graph with the given labels.

§Arguments
  • labels - The labels of the vertices in the graph.
§Notes
  • Labels will be sorted in alphabetical order.
  • No self-loops are created.
§Panics
  • If the labels are not unique.
§Returns

A new graph instance.

Source

fn vertices(&self) -> Set<usize>

Returns the iterator of vertices in the graph.

§Returns

A set representing the vertices in the graph.

Source

fn has_vertex(&self, x: usize) -> bool

Checks if a vertex exists in the graph.

§Arguments
  • x - The index of the vertex.
§Returns

true if the vertex exists, false otherwise.

Source

fn edges(&self) -> Set<(usize, usize)>

Returns the iterator of edges in the graph.

§Returns

A set of tuples representing the edges in the graph.

Source

fn has_edge(&self, x: usize, y: usize) -> bool

Checks if there is an edge between vertices x and y.

§Arguments
  • x - The first vertex.
  • y - The second vertex.
§Panics
  • If any of the vertices are out of bounds.
§Returns

true if there is an edge between x and y, false otherwise.

Source

fn add_edge(&mut self, x: usize, y: usize) -> bool

Adds an edge between vertices x and y.

§Arguments
  • x - The first vertex.
  • y - The second vertex.
§Panics
  • If any of the vertices are out of bounds.
§Returns

true if the edge was added, false if it already existed.

Source

fn del_edge(&mut self, x: usize, y: usize) -> bool

Deletes the edge between vertices x and y.

§Arguments
  • x - The first vertex.
  • y - The second vertex.
§Panics
  • If any of the vertices are out of bounds.
§Returns

true if the edge was deleted, false if it did not exist.

Source

fn from_adjacency_matrix(labels: Labels, adjacency_matrix: Array2<bool>) -> Self

Creates a graph from an adjacency matrix and labels.

§Arguments
  • labels - An iterator over the labels of the vertices.
  • adjacency_matrix - A reference to a 2D array representing the adjacency matrix.
§Returns

A new graph instance.

Source

fn to_adjacency_matrix(&self) -> Array2<bool>

Converts the graph to an adjacency matrix.

§Returns

A 2D array representing the adjacency matrix of the graph.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§