Struct prepona::storage::AdjMap[][src]

pub struct AdjMap<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir = UndirectedEdge> { /* fields omitted */ }

AdjMap is a two-layer hash map in the form of: (source id) -> (destination id) -> (list of edges from source to destination).

Note

From now on

  • |V|: Means number of vertices that are stored in the storage.
  • |Esrc->dst|: Means number of edges from source to destination.
  • |E|: Means number of edges stored in the storage.

Space complexity

Space complexity of AdjMap depends on wether Dir is Directed or Undirected.

  • Directed: For directed graphs AdjMap stores |V| + |E| elements.
  • Undirected: For undirected graphs AdjMap stores each edge twice so it stores |V| + 2*|E| elements.

Generic Parameters

  • W: Weight type associated with edges.
  • E: Edge type that graph uses.
  • Dir: Direction of edges: Directed or Undirected.

Implementations

impl<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir> AdjMap<W, E, Dir>[src]

pub fn init() -> Self[src]

Initializes an empty adjacency map.

AdjMap defines multiple types with different combination of values for generic parameters. These types are:

Returns

An empty AdjMap.

Examples

use prepona::prelude::*;
use prepona::storage::{Map, DiMap};

// To store an undirected graph with usize weights
let map = Map::<usize>::init();

// To store a directed graph with usize weights
let di_map = DiMap::<usize>::init();

Trait Implementations

impl<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir> GraphStorage<W, E, Dir> for AdjMap<W, E, Dir>[src]

fn add_vertex(&mut self) -> usize[src]

Adds a vertex to the graph.

Returns

Unique id of the newly added vertex.

Complexity

O(|1|)

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|)

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]

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(|E|)

Panics

  • If src_id or dst_id is not in range 0..|V|.
  • If there is no edge with id: edge_id from src_id to dst_id.

fn remove_edge_unchecked(
    &mut self,
    src_id: usize,
    dst_id: usize,
    edge_id: usize
) -> E
[src]

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 with edge_id does not exist in the graph.

Complexity

O(|Esrc->dst|)

Panics

  • If src_id or dst_id is not in range 0..|V|.
  • If there is no edge with id: edge_id from src_id to dst_id.

fn vertex_count(&self) -> usize[src]

Returns

Number of vertices in the graph.

Complexity

O(1)

fn edge_count(&self) -> usize[src]

Returns

Number of edges in the graph.

Complexity:

O(1)

fn vertices(&self) -> Vec<usize>[src]

Returns

Id of vertices that are present in the graph.

Complexity

O(|V|)

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 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.

impl<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir> Index<(usize, usize)> for AdjMap<W, E, Dir>[src]

type Output = Vec<E>

The returned type after indexing.

impl<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir> Index<usize> for AdjMap<W, E, Dir>[src]

type Output = HashMap<usize, Vec<E>>

The returned type after indexing.

impl<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir> IndexMut<(usize, usize)> for AdjMap<W, E, Dir>[src]

impl<W: Copy, E: Edge<W> + Copy, Dir: EdgeDir> IndexMut<usize> for AdjMap<W, E, Dir>[src]

Auto Trait Implementations

impl<W, E, Dir> RefUnwindSafe for AdjMap<W, E, Dir> where
    Dir: RefUnwindSafe,
    E: RefUnwindSafe,
    W: RefUnwindSafe

impl<W, E, Dir> Send for AdjMap<W, E, Dir> where
    Dir: Send,
    E: Send,
    W: Send

impl<W, E, Dir> Sync for AdjMap<W, E, Dir> where
    Dir: Sync,
    E: Sync,
    W: Sync

impl<W, E, Dir> Unpin for AdjMap<W, E, Dir> where
    Dir: Unpin,
    E: Unpin,
    W: Unpin

impl<W, E, Dir> UnwindSafe for AdjMap<W, E, Dir> where
    Dir: UnwindSafe,
    E: UnwindSafe,
    W: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.