Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Change Vec to slice throughout
  • Loading branch information
skade committed Oct 28, 2015
commit 0e2e81a24a692705d82a20ba10f9329b8e36a2b7
8 changes: 4 additions & 4 deletions csa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn csa_main_loop(timetable: &[Connection], arrival_station: usize, earliest_arri
});
}

fn csa_print_result(timetable: &Vec<Connection>, in_connection: &[usize], arrival_station: usize) {
fn csa_print_result(timetable: &[Connection], in_connection: &[usize], arrival_station: usize) {
if in_connection[arrival_station] == std::u32::MAX as usize {
println!("NO_SOLUTION");
} else {
Expand All @@ -60,7 +60,7 @@ fn csa_print_result(timetable: &Vec<Connection>, in_connection: &[usize], arriva
println!("");
}

fn csa_compute(timetable: &Vec<Connection>, departure_station: usize, arrival_station: usize, departure_time: u32)
fn csa_compute(timetable: &[Connection], departure_station: usize, arrival_station: usize, departure_time: u32)
{
let mut in_connection = vec!(std::u32::MAX as usize; MAX_STATIONS);
let mut earliest_arrival = vec!(std::u32::MAX; MAX_STATIONS);
Expand All @@ -81,7 +81,7 @@ fn main() {
let timetable = buffered_in.map(|r| { r.ok().expect("failed to read connection line") })
.take_while(|l| { !l.is_empty() })
.map(|l| { Connection::parse(l.trim_right()) })
.collect();
.collect::<Vec<Connection>>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can .collect::<Vec<_>>();


// Responding to requests from stdin

Expand All @@ -98,6 +98,6 @@ fn main() {
let arrival_station = params[1] as usize;
let departure_time = params[2];

csa_compute(&timetable, departure_station, arrival_station, departure_time);
csa_compute(&timetable[..], departure_station, arrival_station, departure_time);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not needed, no? And using a collect for collecting a Vec<()> is code obfuscation and useless memory allocation. Better to use a for loop, it's not evil.

}).collect::<Vec<_>>();
}