about summary refs log tree commit diff
path: root/src/libnum
diff options
context:
space:
mode:
authorMichael Darakananda <pongad@gmail.com>2014-02-06 02:34:33 -0500
committerMichael Darakananda <pongad@gmail.com>2014-02-13 20:12:59 -0500
commitbf1464c413bb2564c7be0eaceef9515bc0f94f1f (patch)
treeb956233c5e7c587d1faecbadb307117cda24952a /src/libnum
parent94d453e459107ed1c5d76f693686b29d31cdc58c (diff)
downloadrust-bf1464c413bb2564c7be0eaceef9515bc0f94f1f.tar.gz
rust-bf1464c413bb2564c7be0eaceef9515bc0f94f1f.zip
Removed num::Orderable
Diffstat (limited to 'src/libnum')
-rw-r--r--src/libnum/bigint.rs56
-rw-r--r--src/libnum/rational.rs19
2 files changed, 10 insertions, 65 deletions
diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs
index 8f632ae639d..345dce12fed 100644
--- a/src/libnum/bigint.rs
+++ b/src/libnum/bigint.rs
@@ -16,9 +16,9 @@ A `BigUint` is represented as an array of `BigDigit`s.
 A `BigInt` is a combination of `BigUint` and `Sign`.
 */
 
+use std::cmp;
 use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
-use std::num;
-use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
+use std::num::{Zero, One, ToStrRadix, FromStrRadix};
 use std::num::{Bitwise, ToPrimitive, FromPrimitive};
 use std::rand::Rng;
 use std::str;
@@ -133,27 +133,9 @@ impl FromStr for BigUint {
 
 impl Num for BigUint {}
 
-impl Orderable for BigUint {
-    #[inline]
-    fn min(&self, other: &BigUint) -> BigUint {
-        if self < other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn max(&self, other: &BigUint) -> BigUint {
-        if self > other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &BigUint, mx: &BigUint) -> BigUint {
-        if self > mx { mx.clone() } else
-        if self < mn { mn.clone() } else { self.clone() }
-    }
-}
-
 impl BitAnd<BigUint, BigUint> for BigUint {
     fn bitand(&self, other: &BigUint) -> BigUint {
-        let new_len = num::min(self.data.len(), other.data.len());
+        let new_len = cmp::min(self.data.len(), other.data.len());
         let anded = vec::from_fn(new_len, |i| {
             // i will never be less than the size of either data vector
             let ai = self.data[i];
@@ -166,7 +148,7 @@ impl BitAnd<BigUint, BigUint> for BigUint {
 
 impl BitOr<BigUint, BigUint> for BigUint {
     fn bitor(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
         let ored = vec::from_fn(new_len, |i| {
             let ai = if i < self.data.len()  { self.data[i]  } else { 0 };
             let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -178,7 +160,7 @@ impl BitOr<BigUint, BigUint> for BigUint {
 
 impl BitXor<BigUint, BigUint> for BigUint {
     fn bitxor(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
         let xored = vec::from_fn(new_len, |i| {
             let ai = if i < self.data.len()  { self.data[i]  } else { 0 };
             let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -223,7 +205,7 @@ impl Unsigned for BigUint {}
 
 impl Add<BigUint, BigUint> for BigUint {
     fn add(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
 
         let mut carry = 0;
         let mut sum = vec::from_fn(new_len, |i| {
@@ -242,7 +224,7 @@ impl Add<BigUint, BigUint> for BigUint {
 
 impl Sub<BigUint, BigUint> for BigUint {
     fn sub(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
 
         let mut borrow = 0;
         let diff = vec::from_fn(new_len, |i| {
@@ -278,7 +260,7 @@ impl Mul<BigUint, BigUint> for BigUint {
         // = a1*b1 * base^2 +
         //   (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
         //   a0*b0
-        let half_len = num::max(s_len, o_len) / 2;
+        let half_len = cmp::max(s_len, o_len) / 2;
         let (sHi, sLo) = cut_at(self,  half_len);
         let (oHi, oLo) = cut_at(other, half_len);
 
@@ -315,7 +297,7 @@ impl Mul<BigUint, BigUint> for BigUint {
 
         #[inline]
         fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
-            let mid = num::min(a.data.len(), n);
+            let mid = cmp::min(a.data.len(), n);
             return (BigUint::from_slice(a.data.slice(mid, a.data.len())),
                     BigUint::from_slice(a.data.slice(0, mid)));
         }
@@ -720,7 +702,7 @@ impl BigUint {
         let mut n: BigUint      = Zero::zero();
         let mut power: BigUint  = One::one();
         loop {
-            let start = num::max(end, unit_len) - unit_len;
+            let start = cmp::max(end, unit_len) - unit_len;
             match uint::parse_bytes(buf.slice(start, end), radix) {
                 Some(d) => {
                     let d: Option<BigUint> = FromPrimitive::from_uint(d);
@@ -941,24 +923,6 @@ impl FromStr for BigInt {
 
 impl Num for BigInt {}
 
-impl Orderable for BigInt {
-    #[inline]
-    fn min(&self, other: &BigInt) -> BigInt {
-        if self < other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn max(&self, other: &BigInt) -> BigInt {
-        if self > other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &BigInt, mx: &BigInt) -> BigInt {
-        if self > mx { mx.clone() } else
-        if self < mn { mn.clone() } else { self.clone() }
-    }
-}
-
 impl Shl<uint, BigInt> for BigInt {
     #[inline]
     fn shl(&self, rhs: &uint) -> BigInt {
diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs
index 698a109a756..a41996d044f 100644
--- a/src/libnum/rational.rs
+++ b/src/libnum/rational.rs
@@ -160,25 +160,6 @@ cmp_impl!(impl TotalEq, equals)
 cmp_impl!(impl Ord, lt, gt, le, ge)
 cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering)
 
-impl<T: Clone + Integer + Ord> Orderable for Ratio<T> {
-    #[inline]
-    fn min(&self, other: &Ratio<T>) -> Ratio<T> {
-        if *self < *other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn max(&self, other: &Ratio<T>) -> Ratio<T> {
-        if *self > *other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &Ratio<T>, mx: &Ratio<T>) -> Ratio<T> {
-        if *self > *mx { mx.clone()} else
-        if *self < *mn { mn.clone() } else { self.clone() }
-    }
-}
-
-
 /* Arithmetic */
 // a/b * c/d = (a*c)/(b*d)
 impl<T: Clone + Integer + Ord>