Start to implement assignment 4
This commit is contained in:
20
src/util.rs
20
src/util.rs
@@ -3,6 +3,14 @@ use std::io;
|
||||
use std::io::{BufRead, BufReader, Error, ErrorKind};
|
||||
use std::vec::Vec;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Graph {
|
||||
nodes: Vec<u32>,
|
||||
edges: Vec<(u32, u32)>,
|
||||
}
|
||||
|
||||
|
||||
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
|
||||
let file = File::open(path)?;
|
||||
let br = BufReader::new(file);
|
||||
@@ -19,3 +27,15 @@ pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
|
||||
}
|
||||
|
||||
|
||||
pub fn read_to_graph(path: &str) -> Result<Graph, io::Error> {
|
||||
let mut g = Graph { nodes: vec![], edges: vec![] };
|
||||
let file = File::open(path)?;
|
||||
let br = BufReader::new(file);
|
||||
|
||||
for line in br.lines() {
|
||||
let line = line?;
|
||||
println!("{:?}", line);
|
||||
}
|
||||
|
||||
Ok(g)
|
||||
}
|
||||
Reference in New Issue
Block a user