about summary refs log tree commit diff
path: root/src/libstd
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/libstd
parent94d453e459107ed1c5d76f693686b29d31cdc58c (diff)
downloadrust-bf1464c413bb2564c7be0eaceef9515bc0f94f1f.tar.gz
rust-bf1464c413bb2564c7be0eaceef9515bc0f94f1f.zip
Removed num::Orderable
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/cmp.rs2
-rw-r--r--src/libstd/hashmap.rs4
-rw-r--r--src/libstd/io/buffered.rs4
-rw-r--r--src/libstd/num/f32.rs60
-rw-r--r--src/libstd/num/f64.rs68
-rw-r--r--src/libstd/num/int_macros.rs29
-rw-r--r--src/libstd/num/mod.rs23
-rw-r--r--src/libstd/num/uint_macros.rs33
-rw-r--r--src/libstd/prelude.rs2
9 files changed, 10 insertions, 215 deletions
diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs
index 1283aba9729..de9f836ca5e 100644
--- a/src/libstd/cmp.rs
+++ b/src/libstd/cmp.rs
@@ -169,6 +169,8 @@ pub trait Ord {
     fn gt(&self, other: &Self) -> bool {  other.lt(self) }
     #[inline]
     fn ge(&self, other: &Self) -> bool { !self.lt(other) }
+
+    // FIXME (#12068): Add min/max/clamp default methods
 }
 
 /// The equivalence relation. Two values may be equivalent even if they are
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index c49294a095f..f8e02c82fcd 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -54,7 +54,7 @@
 
 use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
 use clone::Clone;
-use cmp::{Eq, Equiv};
+use cmp::{Eq, Equiv, max};
 use default::Default;
 #[cfg(not(stage0))] use fmt;
 use hash::Hash;
@@ -376,7 +376,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
     /// cause many collisions and very poor performance. Setting them
     /// manually using this function can expose a DoS attack vector.
     pub fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashMap<K, V> {
-        let cap = num::max(INITIAL_CAPACITY, capacity);
+        let cap = max(INITIAL_CAPACITY, capacity);
         HashMap {
             k0: k0, k1: k1,
             resize_at: resize_at(cap),
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs
index a48403f19a4..231cf6592eb 100644
--- a/src/libstd/io/buffered.rs
+++ b/src/libstd/io/buffered.rs
@@ -10,10 +10,10 @@
 
 //! Buffering wrappers for I/O traits
 
+use cmp;
 use container::Container;
 use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
 use iter::ExactSize;
-use num;
 use option::{Some, None};
 use result::{Ok, Err};
 use vec::{OwnedVector, ImmutableVector, MutableVector};
@@ -104,7 +104,7 @@ impl<R: Reader> Reader for BufferedReader<R> {
     fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
         let nread = {
             let available = if_ok!(self.fill());
-            let nread = num::min(available.len(), buf.len());
+            let nread = cmp::min(available.len(), buf.len());
             vec::bytes::copy_memory(buf, available.slice_to(nread));
             nread
         };
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs
index a4b6aca86f7..9951405fa0c 100644
--- a/src/libstd/num/f32.rs
+++ b/src/libstd/num/f32.rs
@@ -189,42 +189,6 @@ impl Ord for f32 {
     fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
 }
 
-impl Orderable for f32 {
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn min(&self, other: &f32) -> f32 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self < *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn max(&self, other: &f32) -> f32 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self > *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    /// If any of the numbers are `NAN` then `NAN` is returned.
-    #[inline]
-    fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
-        match () {
-            _ if self.is_nan()   => *self,
-            _ if !(*self <= *mx) => *mx,
-            _ if !(*self >= *mn) => *mn,
-            _                    => *self,
-        }
-    }
-}
-
 impl Default for f32 {
     #[inline]
     fn default() -> f32 { 0.0 }
@@ -914,30 +878,6 @@ mod tests {
     }
 
     #[test]
-    fn test_min() {
-        assert_eq!(1f32.min(&2f32), 1f32);
-        assert_eq!(2f32.min(&1f32), 1f32);
-    }
-
-    #[test]
-    fn test_max() {
-        assert_eq!(1f32.max(&2f32), 2f32);
-        assert_eq!(2f32.max(&1f32), 2f32);
-    }
-
-    #[test]
-    fn test_clamp() {
-        assert_eq!(1f32.clamp(&2f32, &4f32), 2f32);
-        assert_eq!(8f32.clamp(&2f32, &4f32), 4f32);
-        assert_eq!(3f32.clamp(&2f32, &4f32), 3f32);
-
-        let nan: f32 = Float::nan();
-        assert!(3f32.clamp(&nan, &4f32).is_nan());
-        assert!(3f32.clamp(&2f32, &nan).is_nan());
-        assert!(nan.clamp(&2f32, &4f32).is_nan());
-    }
-
-    #[test]
     fn test_floor() {
         assert_approx_eq!(1.0f32.floor(), 1.0f32);
         assert_approx_eq!(1.3f32.floor(), 1.0f32);
diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs
index d51f6b602d7..643dcc5bd4b 100644
--- a/src/libstd/num/f64.rs
+++ b/src/libstd/num/f64.rs
@@ -196,42 +196,6 @@ impl Ord for f64 {
     fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
 }
 
-impl Orderable for f64 {
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn min(&self, other: &f64) -> f64 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self < *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn max(&self, other: &f64) -> f64 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self > *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    /// If any of the numbers are `NAN` then `NAN` is returned.
-    #[inline]
-    fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
-        match () {
-            _ if self.is_nan()   => *self,
-            _ if !(*self <= *mx) => *mx,
-            _ if !(*self >= *mn) => *mn,
-            _                    => *self,
-        }
-    }
-}
-
 impl Default for f64 {
     #[inline]
     fn default() -> f64 { 0.0 }
@@ -916,38 +880,6 @@ mod tests {
     }
 
     #[test]
-    fn test_min() {
-        assert_eq!(1f64.min(&2f64), 1f64);
-        assert_eq!(2f64.min(&1f64), 1f64);
-
-        let nan: f64 = Float::nan();
-        assert!(1f64.min(&nan).is_nan());
-        assert!(nan.min(&1f64).is_nan());
-    }
-
-    #[test]
-    fn test_max() {
-        assert_eq!(1f64.max(&2f64), 2f64);
-        assert_eq!(2f64.max(&1f64), 2f64);
-
-        let nan: f64 = Float::nan();
-        assert!(1f64.max(&nan).is_nan());
-        assert!(nan.max(&1f64).is_nan());
-    }
-
-    #[test]
-    fn test_clamp() {
-        assert_eq!(1f64.clamp(&2f64, &4f64), 2f64);
-        assert_eq!(8f64.clamp(&2f64, &4f64), 4f64);
-        assert_eq!(3f64.clamp(&2f64, &4f64), 3f64);
-
-        let nan: f64 = Float::nan();
-        assert!(3f64.clamp(&nan, &4f64).is_nan());
-        assert!(3f64.clamp(&2f64, &nan).is_nan());
-        assert!(nan.clamp(&2f64, &4f64).is_nan());
-    }
-
-    #[test]
     fn test_floor() {
         assert_approx_eq!(1.0f64.floor(), 1.0f64);
         assert_approx_eq!(1.3f64.floor(), 1.0f64);
diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs
index c8d5dc12499..4965d060611 100644
--- a/src/libstd/num/int_macros.rs
+++ b/src/libstd/num/int_macros.rs
@@ -53,24 +53,6 @@ impl Eq for $T {
     fn eq(&self, other: &$T) -> bool { return (*self) == (*other); }
 }
 
-impl Orderable for $T {
-    #[inline]
-    fn min(&self, other: &$T) -> $T {
-        if *self < *other { *self } else { *other }
-    }
-
-    #[inline]
-    fn max(&self, other: &$T) -> $T {
-        if *self > *other { *self } else { *other }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &$T, mx: &$T) -> $T {
-        if *self > *mx { *mx } else
-        if *self < *mn { *mn } else { *self }
-    }
-}
-
 impl Default for $T {
     #[inline]
     fn default() -> $T { 0 }
@@ -458,17 +440,6 @@ mod tests {
     }
 
     #[test]
-    fn test_orderable() {
-        assert_eq!((1 as $T).min(&(2 as $T)), 1 as $T);
-        assert_eq!((2 as $T).min(&(1 as $T)), 1 as $T);
-        assert_eq!((1 as $T).max(&(2 as $T)), 2 as $T);
-        assert_eq!((2 as $T).max(&(1 as $T)), 2 as $T);
-        assert_eq!((1 as $T).clamp(&(2 as $T), &(4 as $T)), 2 as $T);
-        assert_eq!((8 as $T).clamp(&(2 as $T), &(4 as $T)), 4 as $T);
-        assert_eq!((3 as $T).clamp(&(2 as $T), &(4 as $T)), 3 as $T);
-    }
-
-    #[test]
     pub fn test_abs() {
         assert_eq!((1 as $T).abs(), 1 as $T);
         assert_eq!((0 as $T).abs(), 0 as $T);
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs
index 976761b5120..c5510078e39 100644
--- a/src/libstd/num/mod.rs
+++ b/src/libstd/num/mod.rs
@@ -33,23 +33,6 @@ pub trait Num: Eq + Zero + One
              + Div<Self,Self>
              + Rem<Self,Self> {}
 
-pub trait Orderable: Ord {
-    // These should be methods on `Ord`, with overridable default implementations. We don't want
-    // to encumber all implementors of Ord by requiring them to implement these functions, but at
-    // the same time we want to be able to take advantage of the speed of the specific numeric
-    // functions (like the `fmin` and `fmax` intrinsics).
-    fn min(&self, other: &Self) -> Self;
-    fn max(&self, other: &Self) -> Self;
-    fn clamp(&self, mn: &Self, mx: &Self) -> Self;
-}
-
-/// Return the smaller number.
-#[inline(always)] pub fn min<T: Orderable>(x: T, y: T) -> T { x.min(&y) }
-/// Return the larger number.
-#[inline(always)] pub fn max<T: Orderable>(x: T, y: T) -> T { x.max(&y) }
-/// Returns the number constrained within the range `mn <= self <= mx`.
-#[inline(always)] pub fn clamp<T: Orderable>(value: T, mn: T, mx: T) -> T { value.clamp(&mn, &mx) }
-
 /// Defines an additive identity element for `Self`.
 ///
 /// # Deriving
@@ -140,7 +123,7 @@ pub trait Signed: Num
 pub trait Unsigned: Num {}
 
 pub trait Integer: Num
-                 + Orderable
+                 + Ord
                  + Div<Self,Self>
                  + Rem<Self,Self> {
     fn div_rem(&self, other: &Self) -> (Self,Self);
@@ -185,7 +168,7 @@ pub trait Round {
 
 /// Defines constants and methods common to real numbers
 pub trait Real: Signed
-              + Orderable
+              + Ord
               + Round
               + Div<Self,Self> {
     // Common Constants
@@ -434,7 +417,7 @@ pub trait Primitive: Clone
                    + DeepClone
                    + Num
                    + NumCast
-                   + Orderable
+                   + Ord
                    + Bounded {}
 
 /// A collection of traits relevant to primitive signed and unsigned integers
diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs
index eb483843b5d..bbf1c497c2b 100644
--- a/src/libstd/num/uint_macros.rs
+++ b/src/libstd/num/uint_macros.rs
@@ -44,28 +44,6 @@ impl Eq for $T {
     fn eq(&self, other: &$T) -> bool { return (*self) == (*other); }
 }
 
-impl Orderable for $T {
-    #[inline]
-    fn min(&self, other: &$T) -> $T {
-        if *self < *other { *self } else { *other }
-    }
-
-    #[inline]
-    fn max(&self, other: &$T) -> $T {
-        if *self > *other { *self } else { *other }
-    }
-
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    #[inline]
-    fn clamp(&self, mn: &$T, mx: &$T) -> $T {
-        match () {
-            _ if (*self > *mx) => *mx,
-            _ if (*self < *mn) => *mn,
-            _                  => *self,
-        }
-    }
-}
-
 impl Default for $T {
     #[inline]
     fn default() -> $T { 0 }
@@ -330,17 +308,6 @@ mod tests {
     }
 
     #[test]
-    fn test_orderable() {
-        assert_eq!((1 as $T).min(&(2 as $T)), 1 as $T);
-        assert_eq!((2 as $T).min(&(1 as $T)), 1 as $T);
-        assert_eq!((1 as $T).max(&(2 as $T)), 2 as $T);
-        assert_eq!((2 as $T).max(&(1 as $T)), 2 as $T);
-        assert_eq!((1 as $T).clamp(&(2 as $T), &(4 as $T)), 2 as $T);
-        assert_eq!((8 as $T).clamp(&(2 as $T), &(4 as $T)), 4 as $T);
-        assert_eq!((3 as $T).clamp(&(2 as $T), &(4 as $T)), 3 as $T);
-    }
-
-    #[test]
     fn test_div_mod_floor() {
         assert_eq!((10 as $T).div_floor(&(3 as $T)), 3 as $T);
         assert_eq!((10 as $T).mod_floor(&(3 as $T)), 1 as $T);
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index 4849b83037f..3eaa1db87ba 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -59,7 +59,7 @@ pub use iter::{FromIterator, Extendable};
 pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
 pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
 pub use num::{Integer, Real, Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
-pub use num::{Orderable, Signed, Unsigned, Round};
+pub use num::{Signed, Unsigned, Round};
 pub use num::{Primitive, Int, Float, ToStrRadix, ToPrimitive, FromPrimitive};
 pub use path::{GenericPath, Path, PosixPath, WindowsPath};
 pub use ptr::RawPtr;