From 9518fc79eaa9979721abcdb9eaa506a1140cf3fb Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 30 Aug 2012 10:39:28 -0700 Subject: [PATCH] cargo: Fix some lack of knowledge of basic algebraic identities --- src/cargo/cargo.rs | 21 +++------------------ src/libcore/tuple.rs | 40 ++++++---------------------------------- src/libcore/vec.rs | 20 +++----------------- 3 files changed, 12 insertions(+), 69 deletions(-) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index d876a9c679f..9131c07aa55 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -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 = { diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index 2f34e69573f..27b5979f573 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -96,22 +96,9 @@ impl (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, B, C): Eq { @@ -149,24 +136,9 @@ impl (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] diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index dcdea639084..baf6c7c8601 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1443,23 +1443,9 @@ pure fn lt(a: &[T], b: &[T]) -> bool { return a_len < b_len; } -pure fn le(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(a: &[T], b: &[T]) -> bool { !lt(b, a) } -pure fn gt(a: &[T], b: &[T]) -> bool { !le(b, a) } +pure fn le(a: &[T], b: &[T]) -> bool { !lt(b, a) } +pure fn ge(a: &[T], b: &[T]) -> bool { !lt(a, b) } +pure fn gt(a: &[T], b: &[T]) -> bool { lt(b, a) } impl &[T]: Ord { #[inline(always)]