Comparisons!

This commit is contained in:
2018-03-24 12:03:29 -07:00
parent 9c4ea7ae26
commit 6b9783c69a
3 changed files with 24 additions and 13 deletions

View File

@@ -71,20 +71,23 @@ impl PartialOrd for UCN {
impl Ord for UCN {
fn cmp(&self, other: &UCN) -> Ordering {
let mut iter_left = self.contents.iter();
let mut iter_right = other.contents.iter();
match self.contents.len().cmp(&other.contents.len()) {
Ordering::Equal => {
let mut me = self.contents.iter().rev();
let mut them = other.contents.iter().rev();
loop {
match (iter_left.next(), iter_right.next()) {
(None, None) => return Ordering::Equal,
(Some(_), None) => return Ordering::Greater,
(None, Some(_)) => return Ordering::Less,
(Some(x), Some(y)) =>
match x.cmp(y) {
Ordering::Equal => continue,
result => return result
for (m, t) in me.zip(them) {
match m.cmp(t) {
Ordering::Equal =>
continue,
res =>
return res
}
}
Ordering::Equal
}
x => x
}
}
}
@@ -161,5 +164,11 @@ mod test {
ucnx.cmp(&ucny) == Ordering::Greater
}
}
fn self_is_equal(x: Vec<u64>) -> bool {
let val = UCN{ contents: x };
let copy = val.clone();
(&val == &copy) && (val.cmp(&copy) == Ordering::Equal)
}
}
}

View File

@@ -11,13 +11,14 @@
//! when they should use it, and examples. For now, it mostly just fowards
//! off to more detailed modules. Help requested!
extern crate num;
#[cfg(test)]
#[macro_use]
extern crate quickcheck;
extern crate rand;
/// The cryptonum module provides support for large numbers at fixed,
/// cryptographically-relevant sizes.
/// The cryptonum module provides support for large numbers for use in various
/// cryptographically-relevant algorithms.
pub mod cryptonum;
#[cfg(test)]