Skip to content

Commit

Permalink
Fix: Fix build warnings impl
Browse files Browse the repository at this point in the history
  • Loading branch information
badumbatish committed Jul 9, 2024
1 parent d2b7f39 commit 3588cde
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
18 changes: 10 additions & 8 deletions src/adjacency_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ impl GraphStorage for AdjacencyList {
}
}

fn neighbors(&self, vertex: &Vertex) -> Vec<(Vertex, Edge)> {
fn neighbors(&self, vertex: &Vertex) -> Option<Vec<(Vertex, Edge)>> {
if let Some(neighbors) = self.adj_list.get(vertex) {
neighbors
.iter()
.map(|(v, e)| (v.clone(), e.clone()))
.collect()
Some(
neighbors
.iter()
.map(|(v, e)| (v.clone(), e.clone()))
.collect(),
)
} else {
Vec::new()
None
}
}

Expand All @@ -68,7 +70,7 @@ impl GraphStorage for AdjacencyList {
todo!()
}

fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> bool {
fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> Option<bool> {
todo!()
}

Expand All @@ -78,7 +80,7 @@ impl GraphStorage for AdjacencyList {
to: &Vertex,
old_edge: &crate::storage::Edge,
new_edge: &crate::storage::Edge,
) -> bool {
) -> Option<bool> {
todo!()
}
}
20 changes: 13 additions & 7 deletions src/adjacency_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,27 @@ impl GraphStorage for BinaryAdjMatrix {
return self.hash.contains_key(from) && self.hash.contains_key(to);
}

fn neighbors(&self, vertex: &Vertex) -> Vec<(Vertex, crate::storage::Edge)> {
fn neighbors(&self, vertex: &Vertex) -> Option<Vec<(Vertex, Edge)>> {
todo!()
}

fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> bool {
todo!()
fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> Option<bool> {
let index = self.hash.remove(old_vertex);
if index.is_none() {
return Some(false);
} else {
self.hash.insert(new_vertex.clone(), index.unwrap());
return Some(true);
}
}

fn set_edge(
&mut self,
from: &Vertex,
to: &Vertex,
_from: &Vertex,
_to: &Vertex,
_old_edge: &crate::storage::Edge,
_new_edge: &crate::storage::Edge,
) -> bool {
todo!()
) -> Option<bool> {
None
}
}
12 changes: 9 additions & 3 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub trait GraphStorage {
fn edge_size(&self) -> u64;
fn vertex_size(&self) -> u64;
fn add_vertex(&mut self, vertex: &Vertex) -> bool;
fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> bool;
fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> Option<bool>;
fn remove_vertex(&mut self, vertex: &Vertex) -> bool;
fn add_edge(&mut self, from: &Vertex, to: &Vertex, edge: &Edge) -> bool;
fn remove_edge(&mut self, from: &Vertex, to: &Vertex, edge: &Edge) -> bool;
Expand All @@ -63,7 +63,13 @@ pub trait GraphStorage {
to: &Vertex,
old_edge: &crate::storage::Edge,
new_edge: &crate::storage::Edge,
) -> bool;
) -> Option<bool>;
fn has_edge(&self, from: &Vertex, to: &Vertex, edge: &Edge) -> bool;
fn neighbors(&self, vertex: &Vertex) -> Vec<(Vertex, Edge)>;
fn neighbors(&self, vertex: &Vertex) -> Option<Vec<(Vertex, Edge)>>;
}

#[cfg(test)]
mod fixed_storage {}

#[cfg(test)]
mod dynamic_storage {}
17 changes: 14 additions & 3 deletions src/u_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ where
fn remove_edge(&mut self, from: &Vertex, to: &Vertex, edge: &Edge) -> bool;
fn has_vertex(&self, vertex: &Vertex) -> bool;
fn has_edge(&self, from: &Vertex, to: &Vertex, edge: &Edge) -> bool;
fn neighbors(&self, vertex: &Vertex) -> Vec<(Vertex, Edge)>;
fn neighbors(&self, vertex: &Vertex) -> Option<Vec<(Vertex, Edge)>>;
fn set_edge(
&mut self,
from: &Vertex,
to: &Vertex,
old_edge: &Edge,
new_edge: &Edge
) -> bool ;
fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> bool;
) -> Option<bool>;
fn set_vertex(&mut self, old_vertex: &Vertex, new_vertex: &Vertex) -> Option<bool>;
}
}
}
Expand All @@ -59,3 +59,14 @@ where
UGraph { storage: S::new() }
}
}
#[cfg(test)]
mod u_graph {
use crate::adjacency_matrix::BinaryAdjMatrix;

use super::*;
#[test]
fn test() {}
}

#[test]
fn a() {}

0 comments on commit 3588cde

Please sign in to comment.