Skip to content

Commit 8bd9cce

Browse files
committed
Removed arc instances from bfs module
1 parent 0f5f4e8 commit 8bd9cce

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

src/graph.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -974,15 +974,6 @@ impl<T> Graph<T> {
974974
Bfs::new(self)
975975
}
976976

977-
/// Attempts to fetch a reference to a stored vertex id
978-
/// which is equal to the given `VertexId`.
979-
pub(crate) fn fetch_id_ref<'b>(&'b self, id: &VertexId) -> Option<&'b VertexId> {
980-
match self.vertices.get(id) {
981-
Some((_, id_ptr)) => Some(id_ptr.as_ref()),
982-
None => None,
983-
}
984-
}
985-
986977
/// Creates a file with the dot representation of the graph.
987978
/// This method requires the `dot` feature.
988979
///
@@ -1024,14 +1015,14 @@ impl<T> Graph<T> {
10241015
}
10251016

10261017
fn do_add_edge(&mut self, a: &VertexId, b: &VertexId, weight: f32) -> Result<(), GraphErr> {
1027-
let id_ptr1 = if let Some((_, a_prime)) = self.vertices.get(a) {
1028-
a_prime.clone()
1018+
let id_ptr1 = if self.vertices.get(a).is_some() {
1019+
a.clone()
10291020
} else {
10301021
return Err(GraphErr::NoSuchVertex);
10311022
};
10321023

1033-
let id_ptr2 = if let Some((_, b_prime)) = self.vertices.get(b) {
1034-
b_prime.clone()
1024+
let id_ptr2 = if self.vertices.get(b).is_some() {
1025+
b.clone()
10351026
} else {
10361027
return Err(GraphErr::NoSuchVertex);
10371028
};
@@ -1113,6 +1104,15 @@ impl<T> Graph<T> {
11131104
});
11141105
}
11151106

1107+
/// Attempts to fetch a reference to a stored vertex id
1108+
/// which is equal to the given `VertexId`.
1109+
pub(crate) fn fetch_id_ref<'b>(&'b self, id: &VertexId) -> Option<&'b VertexId> {
1110+
match self.vertices.get(id) {
1111+
Some((_, id_ptr)) => Some(id_ptr.as_ref()),
1112+
None => None,
1113+
}
1114+
}
1115+
11161116
/// Returns a reference to the inner edges hash map.
11171117
fn edges_hm_ref(&self) -> Result<(&HashMap<Edge, f32>), GraphErr> {
11181118
Ok(&self.edges)

src/iterators/bfs.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@ use crate::vertex_id::VertexId;
66
use hashbrown::HashSet;
77
#[cfg(not(feature = "no_std"))]
88
use std::collections::VecDeque;
9-
#[cfg(not(feature = "no_std"))]
10-
use std::sync::Arc;
119

1210
#[cfg(feature = "no_std")]
1311
extern crate alloc;
1412
#[cfg(feature = "no_std")]
15-
use alloc::{collections::vec_deque::VecDeque, sync::Arc};
13+
use alloc::{collections::vec_deque::VecDeque};
1614

1715
#[cfg(feature = "no_std")]
1816
use alloc::vec::Vec;
1917

2018
#[derive(Debug)]
2119
/// Breadth-First Iterator
2220
pub struct Bfs<'a, T> {
23-
queue: VecDeque<Arc<VertexId>>,
24-
current_ptr: Option<Arc<VertexId>>,
25-
visited_set: HashSet<Arc<VertexId>>,
26-
roots_stack: Vec<Arc<VertexId>>,
21+
queue: VecDeque<VertexId>,
22+
current_ptr: Option<VertexId>,
23+
visited_set: HashSet<VertexId>,
24+
roots_stack: Vec<VertexId>,
2725
iterable: &'a Graph<T>,
2826
}
2927

@@ -32,7 +30,7 @@ impl<'a, T> Bfs<'a, T> {
3230
let mut roots_stack = Vec::with_capacity(graph.roots_count());
3331

3432
for v in graph.roots() {
35-
roots_stack.push(Arc::from(*v));
33+
roots_stack.push(v.clone());
3634
}
3735

3836
let current_ptr = roots_stack.pop();
@@ -66,8 +64,8 @@ impl<'a, T> Iterator for Bfs<'a, T> {
6664
// and check their visited status.
6765
for n in self.iterable.out_neighbors(current_ptr.as_ref()) {
6866
if !self.visited_set.contains(n) {
69-
self.visited_set.insert(Arc::from(*n));
70-
self.queue.push_back(Arc::from(*n));
67+
self.visited_set.insert(n.clone());
68+
self.queue.push_back(n.clone());
7169

7270
return self.iterable.fetch_id_ref(n);
7371
}

0 commit comments

Comments
 (0)