diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-02-01 23:49:44 -0500 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-02-01 23:49:44 -0500 |
commit | 0bf7f32473a86bd4bb029b5dd61a3cb1d19a31ca (patch) | |
tree | c2a249d7c15ec00d45480eed9ea3bdd32d38940e /src/utils | |
parent | 67ff2f28eb1c60f022f64305bb25e2971fb1e716 (diff) |
Optimizing processes...
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/gen_util.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs index 73c04371..04417dab 100644 --- a/src/utils/gen_util.rs +++ b/src/utils/gen_util.rs @@ -59,3 +59,29 @@ pub fn get_simple_byte_values(bytes: u64, spacing: bool) -> (f64, String) { _ => (bytes as f64 / 1_000_000_000_000.0, "TB".to_string()), } } + +/// Gotta get partial ordering? No problem, here's something to deal with it~ +pub fn get_ordering<T: std::cmp::PartialOrd>( + a_val: T, b_val: T, reverse_order: bool, +) -> std::cmp::Ordering { + match a_val.partial_cmp(&b_val) { + Some(x) => match x { + Ordering::Greater => { + if reverse_order { + std::cmp::Ordering::Less + } else { + std::cmp::Ordering::Greater + } + } + Ordering::Less => { + if reverse_order { + std::cmp::Ordering::Greater + } else { + std::cmp::Ordering::Less + } + } + Ordering::Equal => Ordering::Equal, + }, + None => Ordering::Equal, + } +} |