Skip to content

Commit a0c15c6

Browse files
removing the hashset
1 parent fd33a44 commit a0c15c6

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/bfs.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ impl Graph {
2626
/// Naive BFS implementation using Vec as a queue (intentionally slow)
2727
/// Returns the order in which nodes were visited
2828
pub fn bfs_naive(graph: &Graph, start: usize) -> VecDeque<usize> {
29-
let mut visited = HashSet::new();
30-
let mut queue = VecDeque::with_capacity(256); // Using Vec instead of VecDeque - intentionally inefficient!
29+
let mut visited = [false; 256];
30+
let mut queue = VecDeque::with_capacity(256);
3131
let mut result = VecDeque::with_capacity(256);
3232

3333
queue.push_back(start);
34-
visited.insert(start);
34+
visited[start] = true;
3535

3636
while let Some(node) = queue.pop_front() {
3737
result.push_back(node);
3838

3939
if let Some(neighbors) = graph.adjacency.get(node) {
4040
for &neighbor in neighbors {
41-
if visited.insert(neighbor) {
42-
queue.push_back(neighbor);
43-
}
41+
visited[neighbor] = true;
42+
queue.push_back(neighbor);
4443
}
4544
}
4645
}

0 commit comments

Comments
 (0)