Comparisons!
This commit is contained in:
@@ -9,6 +9,7 @@ license-file = "LICENSE"
|
||||
repository = "https://github.com/acw/simple_crypto"
|
||||
|
||||
[dependencies]
|
||||
num = "^0.1.42"
|
||||
rand = "^0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -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 == ©) && (val.cmp(©) == Ordering::Equal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user