Struct prepona::storage::AdjMatrix [−][src]
pub struct AdjMatrix<W, E: Edge<W>, Dir: EdgeDir = UndirectedEdge> { /* fields omitted */ }
AdjMatrix
is a matrix used to represent a finite graph.
The elements of the matrix indicate whether pairs of vertices are adjacent or not in the graph.
Note
From now on
- |V|: Means total number of vertices that are stored in the storage.
Note that this is different from number of vertices that are present in the graph.
Because even if you remove a vertex from storage, the allocated memory for that vertex will not get freed and will be reused again when adding a new vertex.
You can retrieve the amount of |V| using
total_vertex_count
function(as opposed to number of vertices present in the graph which can be retrieved usingvertex_count
function). For more info and examples refer tototal_vertex_count
documentation. - |E|: Means number of edges present in the graph.
- |Eout|: Means number of edges exiting a vertex(out degree of the vertex).
- |Esrc->dst|: Means number of edges from vertex with id:
src
to vertex with id:dst
.
Space complexity
Space complexity of AdjMatrix
depends on wether Dir
is Directed
or Undirected
.
- Directed: For directed graphs
AdjMatrix
stores matrix with |V|2 + |E| elements. - Undirected: For undirected graphs
AdjMatrix
stores a lower triangle matrix with (|V|2 + |V|)/2 + |E| elements.
Generic Parameters
W
: Weight type associated with edges.E
: Edge type that graph uses.Dir
: Direction of edges:Directed
orUndirected
(default value).
Implementations
impl<W, E: Edge<W>, Dir: EdgeDir> AdjMatrix<W, E, Dir>
[src]
impl<W, E: Edge<W>, Dir: EdgeDir> AdjMatrix<W, E, Dir>
[src]pub fn init() -> Self
[src]
Initializes an empty adjacency matrix.
AdjMatrix
defines multiple types with different combination of values for generic parameters.
These types are:
Mat
: An adjacency matrix that usesundirected
default edges
.DiMat
: An adjacency matrix that usesdirected
default edges
.FlowMat
: An adjacency matrix that usesundirected
flow edges
.DiFlowMat
: An adjacency matrix that usesdirected
flow edges
.
Returns
An empty AdjMatrix
.
Examples
use prepona::prelude::*; use prepona::storage::{Mat, DiMat}; // To store an undirected graph with usize weights let mat = Mat::<usize>::init(); // To store a directed graph with usize weights let di_mat = DiMat::<usize>::init();
pub fn total_vertex_count(&self) -> usize
[src]
Trait Implementations
impl<W: Any, E: Edge<W>, Dir: EdgeDir> GraphStorage<W, E, Dir> for AdjMatrix<W, E, Dir>
[src]
impl<W: Any, E: Edge<W>, Dir: EdgeDir> GraphStorage<W, E, Dir> for AdjMatrix<W, E, Dir>
[src]fn add_vertex(&mut self) -> usize
[src]
fn remove_vertex_unchecked(&mut self, vertex_id: usize)
[src]
Removes the vertex with id: vertex_id
from graph.
Arguments
vertex_id
: Id of the vertex to be removed.
Complexity
O(|V|)
Panics
If vertex_id
is not in range 0..|V|.
fn add_edge_unchecked(&mut self, src_id: usize, dst_id: usize, edge: E) -> usize
[src]
Adds edge
from vertex with id :src_id
to vertex with id: dst_id
.
Arguments
src_id
: Id of the source vertex.dst_id
: Id of the destination vertex.edge
: Edge to be added from source to destination.
Returns
Unique id of the newly added edge.
Complexity
O(1)
Panics
If src_id
or dst_id
is not in 0..|V| range.
fn update_edge_unchecked(
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize,
edge: E
)
[src]
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize,
edge: E
)
Replaces the edge with id: edge_id
with edge
.
Arguments
src_id
: Id of source vertex.dst_id
: Id of destination vertex.edge_id
: Id of the to be updated edge.edge
: New edge to replace the old one.
Complexity
O(|Esrc->dst|)
Panics
- If
src_id
ordst_id
is not in range 0..|V|.
fn remove_edge_unchecked(
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> E
[src]
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> E
Removes the edge with id: edge_id
.
Arguments
src_id
: Id of source vertex.dst_id
: Id of destination vertex.edge_id
: Id of edge to be removed.
Returns
Some
: Containing the removed edge.None
: If edge withedge_id
does not exist in the graph.
Complexity
O(|Esrc->dst|)
Panics
- If
src_id
ordst_id
is not in range 0..|V|. - If there is no edge with id:
edge_id
fromsrc_id
todst_id
.
fn vertex_count(&self) -> usize
[src]
fn edge_count(&self) -> usize
[src]
fn vertices(&self) -> Vec<usize>
[src]
fn edges_from_unchecked(&self, src_id: usize) -> Vec<(usize, &E)>
[src]
Arguments
src_id
: Id of the source vertex.
Returns
- All edges from the source vertex in the format of: (
dst_id
,edge
)
Complexity
O(|E*|)
Panics
If src_id
is not in range 0..|V|.
fn neighbors_unchecked(&self, src_id: usize) -> Vec<usize>
[src]
Arguments:
src_id
: Id of the source vertex.
Returns
Id of vertices accessible from source vertex using one edge.
Complexity O(|V|)
Panics
If src_id
is not in range 0..|V|.
fn edges_between_unchecked(&self, src_id: usize, dst_id: usize) -> Vec<&E>
[src]
Arguments
src_id
: Id of source vertex.dst_id
: Id of destination vertex.
Returns
Edges from source vertex to destination vertex.
Complexity
O(|Esrc->dst|)
Panics
- If
src_id
ordst_id
is not in range 0..|V|.
fn contains_vertex(&self, vertex_id: usize) -> bool
[src]
Arguments
vertex_id
: Id of the vertex to search for its existence in the storage.
Returns
true
: If storage contains the vertex with id:vertex_id
.false
: Otherwise.
fn contains_edge(&self, edge_id: usize) -> bool
[src]
Arguments
edge_id
: Id of the edge to search for its existence in the storage.
Returns
true
: If storage contains the edge with id:edge_id
.false
: Otherwise.
fn remove_vertex(&mut self, vertex_id: usize) -> Result<()>
[src]
fn add_edge(&mut self, src_id: usize, dst_id: usize, edge: E) -> Result<usize>
[src]
fn update_edge(
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize,
edge: E
) -> Result<()>
[src]
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize,
edge: E
) -> Result<()>
fn remove_edge(
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> Result<E>
[src]
&mut self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> Result<E>
fn edges_between(&self, src_id: usize, dst_id: usize) -> Result<Vec<&E>>
[src]
fn edge_between(
&self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> Result<&E>
[src]
&self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> Result<&E>
fn edge_between_unchecked(
&self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> &E
[src]
&self,
src_id: usize,
dst_id: usize,
edge_id: usize
) -> &E
fn edge(&self, edge_id: usize) -> Result<&E>
[src]
fn edge_unchecked(&self, edge_id: usize) -> &E
[src]
fn has_any_edge(&self, src_id: usize, dst_id: usize) -> Result<bool>
[src]
fn has_any_edge_unchecked(&self, src_id: usize, dst_id: usize) -> bool
[src]
fn edges(&self) -> Vec<(usize, usize, &E)>
[src]
fn as_directed_edges(&self) -> Vec<(usize, usize, &E)>
[src]
fn edges_from(&self, src_id: usize) -> Result<Vec<(usize, &E)>>
[src]
fn neighbors(&self, src_id: usize) -> Result<Vec<usize>>
[src]
fn is_directed(&self) -> bool
[src]
fn is_undirected(&self) -> bool
[src]
impl<W: Any, E: Edge<W>, Dir: EdgeDir> Index<(usize, usize)> for AdjMatrix<W, E, Dir>
[src]
impl<W: Any, E: Edge<W>, Dir: EdgeDir> Index<(usize, usize)> for AdjMatrix<W, E, Dir>
[src]Auto Trait Implementations
impl<W, E, Dir> RefUnwindSafe for AdjMatrix<W, E, Dir> where
Dir: RefUnwindSafe,
E: RefUnwindSafe,
W: RefUnwindSafe,
impl<W, E, Dir> RefUnwindSafe for AdjMatrix<W, E, Dir> where
Dir: RefUnwindSafe,
E: RefUnwindSafe,
W: RefUnwindSafe,
impl<W, E, Dir> UnwindSafe for AdjMatrix<W, E, Dir> where
Dir: UnwindSafe,
E: UnwindSafe,
W: UnwindSafe,
impl<W, E, Dir> UnwindSafe for AdjMatrix<W, E, Dir> where
Dir: UnwindSafe,
E: UnwindSafe,
W: UnwindSafe,