Run rustfmt on all rs files

This commit is contained in:
Felix Martin 2020-12-03 19:52:15 -05:00
parent 778b665ae0
commit b31fe7176c
5 changed files with 118 additions and 114 deletions

View File

@ -1,16 +1,17 @@
mod merge_sort;
mod min_cut;
mod quick_sort;
mod ssc;
mod min_cut;
mod util;
use crate::util::read_to_graph;
use crate::util::read_to_directed_graph;
use crate::util::read_to_vector;
use crate::merge_sort::merge_sort_inversions;
use crate::min_cut::min_cut;
use crate::quick_sort::quick_sort;
use crate::merge_sort::merge_sort_inversions;
use crate::ssc::ssc;
use crate::util::read_to_directed_graph;
use crate::util::read_to_vector;
#[allow(dead_code)]
fn c1a2() {

View File

@ -1,5 +1,5 @@
use rand::Rng;
use crate::util::Graph;
use rand::Rng;
use std::convert::TryInto;
pub fn min_cut(mut g: Graph) -> u32 {
@ -24,7 +24,7 @@ pub fn min_cut(mut g: Graph) -> u32 {
}
// make sure lower node comes first
if g.edges[i].0 > g.edges[i].1 {
g.edges[i] = (g.edges[i].1, g.edges[i]. 0);
g.edges[i] = (g.edges[i].1, g.edges[i].0);
}
if g.edges[i].0 == g.edges[i].1 {

View File

@ -1,7 +1,6 @@
use std::cmp::PartialOrd;
fn median_of_three<T: PartialOrd + Copy>( v: &[T]) -> usize {
fn median_of_three<T: PartialOrd + Copy>(v: &[T]) -> usize {
if v.len() < 3 {
return 0;
}
@ -20,17 +19,17 @@ fn median_of_three<T: PartialOrd + Copy>( v: &[T]) -> usize {
return left;
} else if median == v[middle] {
return middle;
} else if median == v[right]{
} else if median == v[right] {
return right;
} else {
panic!("Did not find median in values!");
}
}
fn bubble_sort<T: PartialOrd>( v: &mut [T]) -> () {
fn bubble_sort<T: PartialOrd>(v: &mut [T]) -> () {
let mut unsorted = true;
if v.len() <= 1 {
return
return;
}
while unsorted {
unsorted = false;
@ -41,10 +40,9 @@ fn bubble_sort<T: PartialOrd>( v: &mut [T]) -> () {
}
}
}
}
pub fn quick_sort<T: PartialOrd + Copy>( v: &mut [T], comp_acc: &mut usize) -> () {
pub fn quick_sort<T: PartialOrd + Copy>(v: &mut [T], comp_acc: &mut usize) -> () {
if v.len() <= 1 {
return;
}

View File

@ -24,9 +24,11 @@ pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
Ok(v)
}
pub fn read_to_graph(path: &str) -> Result<Graph, io::Error> {
let mut g = Graph { nodes: vec![], edges: vec![] };
let mut g = Graph {
nodes: vec![],
edges: vec![],
};
let file = File::open(path)?;
let br = BufReader::new(file);
@ -51,7 +53,10 @@ pub fn read_to_graph(path: &str) -> Result<Graph, io::Error> {
}
pub fn read_to_directed_graph(path: &str) -> Result<Graph, io::Error> {
let mut g = Graph { nodes: vec![], edges: vec![] };
let mut g = Graph {
nodes: vec![],
edges: vec![],
};
let file = File::open(path)?;
let br = BufReader::new(file);