diff options
author | JSDurand <mmemmew@gmail.com> | 2023-03-14 23:11:09 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-03-14 23:11:09 +0800 |
commit | dca341dbb54737e8cc14a41088e23d23f7eb385e (patch) | |
tree | baa16096f3afd64a707591ef863fb96d3855d3a5 /src/lib.rs | |
parent | 89e82439186c6dfa48a73bddc0908a494fbd4394 (diff) |
Implement the correct solution
Now the correct solution, as suggested by the professor, is
implemented as the function `smi`. :D
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -14,6 +14,10 @@ use rand::{ use std::collections::HashSet; +pub mod incremental; + +pub use incremental::smi; + /// Adjacency set representation type Graph = Vec<HashSet<usize>>; @@ -275,19 +279,24 @@ mod tests { }; let mut count = 0; - let _sorted = sm(input.as_slice(), &mut count); - // println!( - // "sorted = {:?}", - // sorted - // .into_iter() - // .map(|x| *input.get(x).unwrap()) - // .collect::<Vec<_>>() - // ); + let sorted = sm(input.as_slice(), &mut count); + + let sorted: Vec<_> = sorted.into_iter().map(|x| *input.get(x).unwrap()).collect(); + + let mut really_sorted = input; + + // floats are not totally ordered, so there is no default + // method to sort a vector of floats. + really_sorted.sort_unstable_by(|x, y| x.partial_cmp(y).unwrap()); + + assert_eq!(sorted, really_sorted); + + // println!("sorted = {:?}", sorted,); println!( "n = {n}, count = {count}, nlog(n) = {}", - n * ((n as f32).log2() as usize) + n * ((n as f32).log2().ceil() as usize) ); } } |