about summary refs log tree commit diff
path: root/src/libcore/vec.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-08-29 19:23:15 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-08-29 19:23:15 -0700
commita1c11cab2dc56483cf9fe6d25af43b2f602d5155 (patch)
tree7eb884301bb31d4bed8d99c26cd38109b64ac41e /src/libcore/vec.rs
parent70d3633c0b66c247b97f721653d33264ddfc680f (diff)
rustc: Make `<=`, `>=`, and `>` use traits as well
Diffstat (limited to 'src/libcore/vec.rs')
-rw-r--r--src/libcore/vec.rs48
1 files changed, 39 insertions, 9 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index ae08aad8138..dcdea639084 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1443,25 +1443,55 @@ 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) }
+
 impl<T: Ord> &[T]: Ord {
     #[inline(always)]
-    pure fn lt(&&other: &[T]) -> bool {
-        lt(self, other)
-    }
+    pure fn lt(&&other: &[T]) -> bool { lt(self, other) }
+    #[inline(always)]
+    pure fn le(&&other: &[T]) -> bool { le(self, other) }
+    #[inline(always)]
+    pure fn ge(&&other: &[T]) -> bool { ge(self, other) }
+    #[inline(always)]
+    pure fn gt(&&other: &[T]) -> bool { gt(self, other) }
 }
 
 impl<T: Ord> ~[T]: Ord {
     #[inline(always)]
-    pure fn lt(&&other: ~[T]) -> bool {
-        lt(self, other)
-    }
+    pure fn lt(&&other: ~[T]) -> bool { lt(self, other) }
+    #[inline(always)]
+    pure fn le(&&other: ~[T]) -> bool { le(self, other) }
+    #[inline(always)]
+    pure fn ge(&&other: ~[T]) -> bool { ge(self, other) }
+    #[inline(always)]
+    pure fn gt(&&other: ~[T]) -> bool { gt(self, other) }
 }
 
 impl<T: Ord> @[T]: Ord {
     #[inline(always)]
-    pure fn lt(&&other: @[T]) -> bool {
-        lt(self, other)
-    }
+    pure fn lt(&&other: @[T]) -> bool { lt(self, other) }
+    #[inline(always)]
+    pure fn le(&&other: @[T]) -> bool { le(self, other) }
+    #[inline(always)]
+    pure fn ge(&&other: @[T]) -> bool { ge(self, other) }
+    #[inline(always)]
+    pure fn gt(&&other: @[T]) -> bool { gt(self, other) }
 }
 
 #[cfg(notest)]