summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-03-14 23:11:09 +0800
committerJSDurand <mmemmew@gmail.com>2023-03-14 23:11:09 +0800
commitdca341dbb54737e8cc14a41088e23d23f7eb385e (patch)
treebaa16096f3afd64a707591ef863fb96d3855d3a5 /src/lib.rs
parent89e82439186c6dfa48a73bddc0908a494fbd4394 (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.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c474398..ff309d1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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)
);
}
}