Skip to content

Instantly share code, notes, and snippets.

@EntilZha
Last active February 24, 2016 18:12
Show Gist options
  • Save EntilZha/c45382defea63f961701 to your computer and use it in GitHub Desktop.
Save EntilZha/c45382defea63f961701 to your computer and use it in GitHub Desktop.
use std::collections::HashMap;
#[derive(Debug)]
pub struct Graph<V: Copy, E: Copy> {
pub vertexes: HashMap<usize, Vertex<V>>,
pub edges: HashMap<(usize, usize), E>,
adjacency_matrix: Vec<Vec<bool>>
}
#[derive(Debug)]
pub struct Vertex<V: Copy> {
pub value: V,
pub neighbors: Vec<usize>
}
impl<V: Copy, E: Copy> Graph<V, E> {
pub fn new(vertex_list: &Vec<(usize, V)>, edge_list: &Vec<(usize, usize, E)>) -> Graph<V, E> {
let mut vertexes: HashMap<usize, Vertex<V>> = HashMap::new();
for v in vertex_list {
let mut new_v = Vertex {value: v.1, neighbors: Vec::new()};
vertexes.insert(v.0, new_v);
}
let n_vertexes: usize = vertexes.len();
let mut adjacency_matrix: Vec<Vec<bool>> = vec![vec![false; n_vertexes]; n_vertexes];
let mut edges: HashMap<(usize, usize), E> = HashMap::new();
for edge in edge_list {
adjacency_matrix[edge.0][edge.1] = true;
vertexes[&edge.0].neighbors.push(edge.1);
edges.insert((edge.0, edge.1), edge.2);
}
Graph { vertexes: vertexes, edges: edges, adjacency_matrix: adjacency_matrix }
}
pub fn find_path(&self) -> Option<Vec<Vertex<V>>> {
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment