Skip to content

Commit

Permalink
fix text file index shift
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Nov 13, 2024
1 parent fd9807d commit cdbd5e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/graph/directed_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,18 @@ impl DirectedGraph {

// Parse each line as two integers (tail and head)
let mut parts = line.split_whitespace();
let tail: usize = parts
let mut tail: usize = parts
.next()
.ok_or(GraphError::VertexNotFound)?
.parse()
.unwrap();
let head: usize = parts
tail -= 1; // because text files are 1-indexed
let mut head: usize = parts
.next()
.ok_or(GraphError::VertexNotFound)?
.parse()
.unwrap();
head -= 1; // because text files are 1-indexed

// Update max vertex index to determine the number of vertices needed
max_vertex_index = max_vertex_index.max(tail).max(head);
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use algorithms_illuminated::graph::DirectedGraph;
fn main() {
let graph = DirectedGraph::build_from_file("src/graph/txt/graph_tet.txt").unwrap();
let graph = DirectedGraph::build_from_file("src/graph/txt/graph_test.txt").unwrap();
graph.print_graph();
}

0 comments on commit cdbd5e3

Please sign in to comment.