cargo: Fix some lack of knowledge of basic algebraic identities

This commit is contained in:
Patrick Walton 2012-08-30 10:39:28 -07:00
parent 45e46f5fc0
commit 9518fc79ea
3 changed files with 12 additions and 69 deletions

View File

@ -42,24 +42,9 @@ impl package : cmp::Ord {
if self.versions.lt(other.versions) { return true; }
return false;
}
pure fn le(&&other: package) -> bool {
if self.name.lt(other.name) { return true; }
if other.name.lt(self.name) { return false; }
if self.uuid.lt(other.uuid) { return true; }
if other.uuid.lt(self.uuid) { return false; }
if self.url.lt(other.url) { return true; }
if other.url.lt(self.url) { return false; }
if self.method.lt(other.method) { return true; }
if other.method.lt(self.method) { return false; }
if self.description.lt(other.description) { return true; }
if other.description.lt(self.description) { return false; }
if self.tags.lt(other.tags) { return true; }
if other.tags.lt(self.tags) { return false; }
if self.versions.le(other.versions) { return true; }
return false;
}
pure fn ge(&&other: package) -> bool { !other.lt(self) }
pure fn gt(&&other: package) -> bool { !other.le(self) }
pure fn le(&&other: package) -> bool { !other.lt(self) }
pure fn ge(&&other: package) -> bool { !self.lt(other) }
pure fn gt(&&other: package) -> bool { other.lt(self) }
}
type local_package = {

View File

@ -96,22 +96,9 @@ impl<A: Ord, B: Ord> (A, B): Ord {
}
}
}
pure fn le(&&other: (A, B)) -> bool {
match self {
(self_a, self_b) => {
match other {
(other_a, other_b) => {
if self_a.lt(other_a) { return true; }
if other_a.lt(self_a) { return false; }
if self_b.le(other_b) { return true; }
return false;
}
}
}
}
}
pure fn ge(&&other: (A, B)) -> bool { !other.lt(self) }
pure fn gt(&&other: (A, B)) -> bool { !other.ge(self) }
pure fn le(&&other: (A, B)) -> bool { !other.lt(self) }
pure fn ge(&&other: (A, B)) -> bool { !self.lt(other) }
pure fn gt(&&other: (A, B)) -> bool { other.lt(self) }
}
impl<A: Eq, B: Eq, C: Eq> (A, B, C): Eq {
@ -149,24 +136,9 @@ impl<A: Ord, B: Ord, C: Ord> (A, B, C): Ord {
}
}
}
pure fn le(&&other: (A, B, C)) -> bool {
match self {
(self_a, self_b, self_c) => {
match other {
(other_a, other_b, other_c) => {
if self_a.lt(other_a) { return true; }
if other_a.lt(self_a) { return false; }
if self_b.lt(other_b) { return true; }
if other_b.lt(self_b) { return false; }
if self_c.le(other_c) { return true; }
return false;
}
}
}
}
}
pure fn ge(&&other: (A, B, C)) -> bool { !other.lt(self) }
pure fn gt(&&other: (A, B, C)) -> bool { !other.ge(self) }
pure fn le(&&other: (A, B, C)) -> bool { !other.lt(self) }
pure fn ge(&&other: (A, B, C)) -> bool { !self.lt(other) }
pure fn gt(&&other: (A, B, C)) -> bool { other.lt(self) }
}
#[test]

View File

@ -1443,23 +1443,9 @@ pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
return a_len < b_len;
}
pure fn le<T: Ord>(a: &[T], b: &[T]) -> bool {
let (a_len, b_len) = (a.len(), b.len());
let mut end = uint::min(&a_len, &b_len);
let mut i = 0;
while i < end {
let (c_a, c_b) = (&a[i], &b[i]);
if *c_a < *c_b { return true; }
if *c_a > *c_b { return false; }
i += 1;
}
return a_len <= b_len;
}
pure fn ge<T: Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
pure fn gt<T: Ord>(a: &[T], b: &[T]) -> bool { !le(b, a) }
pure fn le<T: Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
pure fn ge<T: Ord>(a: &[T], b: &[T]) -> bool { !lt(a, b) }
pure fn gt<T: Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) }
impl<T: Ord> &[T]: Ord {
#[inline(always)]