diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-08-30 10:39:28 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-08-30 10:39:28 -0700 |
| commit | 9518fc79eaa9979721abcdb9eaa506a1140cf3fb (patch) | |
| tree | 0c78930df57c3b619bd4065b1ff36c7825f814ef /src/libcore | |
| parent | 45e46f5fc0e78f5855e8870a6e3eb2a0a7e5ae50 (diff) | |
cargo: Fix some lack of knowledge of basic algebraic identities
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/tuple.rs | 40 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 20 |
2 files changed, 9 insertions, 51 deletions
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: 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] 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<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)] |
