Skip to content

Commit 2f4b2c4

Browse files
removing the hashset
1 parent fd33a44 commit 2f4b2c4

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/bfs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +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; 10000];
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) {
41+
if !visited[neighbor] {
42+
visited[neighbor] = true;
4243
queue.push_back(neighbor);
4344
}
4445
}

0 commit comments

Comments
 (0)