Initial commit!

This commit is contained in:
2018-09-26 14:47:30 -05:00
commit 3b68363b49
389 changed files with 1415972 additions and 0 deletions

42
src/unsigned/cmp.rs Normal file
View File

@@ -0,0 +1,42 @@
use std::cmp::*;
pub fn compare(a: &[u64], b: &[u64]) -> Ordering {
assert_eq!(a.len(), b.len(), "Incompatible numbers in comparison");
let mut i = (a.len() - 1) as isize;
while i >= 0 {
let iu = i as usize;
match a[iu].cmp(&b[iu]) {
Ordering::Greater => return Ordering::Greater,
Ordering::Less => return Ordering::Less,
Ordering::Equal => i -= 1
}
}
Ordering::Equal
}
macro_rules! cmp_impls {
($name: ident) => {
impl PartialEq for $name {
fn eq(&self, rhs: &$name) -> bool {
compare(&self.value, &rhs.value) == Ordering::Equal
}
}
impl Eq for $name {}
impl PartialOrd for $name {
fn partial_cmp(&self, rhs: &$name) -> Option<Ordering> {
Some(compare(&self.value, &rhs.value))
}
}
impl Ord for $name {
fn cmp(&self, rhs: &$name) -> Ordering {
compare(&self.value, &rhs.value)
}
}
}
}