Skip to content

Commit

Permalink
impl graph via vec instead of a hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Dec 8, 2024
1 parent 5b99148 commit 89b7824
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 105 deletions.
19 changes: 9 additions & 10 deletions src/graph/directed_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ use std::{

use super::{GraphError, VertexIndex};

/// representing a graph using an adjacency list which is
/// 1) An array containing the graph vertices
/// 2) An array containing the graph edges
/// 3) For each edge, a pointer to each of its two endpoints
/// 4) for each vertex, a pointer to each of the incident edges
///
/// for directed graph:
/// each edge keeps track of which endpoint is tail and which endpoint is head
/// each vertex maintains two arrays of pointers, one for the outgoing edges and one for the incoming edges
///
// representing a graph using an adjacency list which is
// 1) An array containing the graph vertices
// 2) An array containing the graph edges
// 3) For each edge, a pointer to each of its two endpoints
// 4) for each vertex, a pointer to each of the incident edges
//
// for directed graph:
// each edge keeps track of which endpoint is tail and which endpoint is head
// each vertex maintains two arrays of pointers, one for the outgoing edges and one for the incoming edges

type VertexRc = Rc<RefCell<Vertex>>;
type VertexWeak = Weak<RefCell<Vertex>>;
Expand Down
2 changes: 1 addition & 1 deletion src/graph/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub enum GraphError {
}

pub trait Graph {
fn add_vertex(&mut self, index: VertexIndex, value: char);
fn add_vertex(&mut self);
fn add_edge(&mut self, from: VertexIndex, to: VertexIndex) -> Result<(), GraphError>;
}
Loading

0 comments on commit 89b7824

Please sign in to comment.