Skip to content

Removed num::Orderable #12061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use std::cast::{transmute, transmute_mut, transmute_mut_region};
use std::cast;
use std::cell::{Cell, RefCell};
use std::mem;
use std::cmp;
use std::num;
use std::kinds::marker;
use std::rc::Rc;
Expand Down Expand Up @@ -183,7 +184,7 @@ impl Arena {
// Functions for the POD part of the arena
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
// Allocate a new chunk.
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
self.pod_head =
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
Expand Down Expand Up @@ -223,7 +224,7 @@ impl Arena {
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
-> (*u8, *u8) {
// Allocate a new chunk.
let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
self.head =
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);
Expand Down
5 changes: 2 additions & 3 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use std::cmp;
use std::iter::RandomAccessIterator;
use std::iter::{Rev, Enumerate, Repeat, Map, Zip};
use std::num;
use std::ops;
use std::uint;
use std::vec;
Expand Down Expand Up @@ -846,7 +845,7 @@ impl MutableSet<uint> for BitvSet {
}
let nbits = self.capacity();
if value >= nbits {
let newsize = num::max(value, nbits * 2) / uint::BITS + 1;
let newsize = cmp::max(value, nbits * 2) / uint::BITS + 1;
assert!(newsize > self.bitv.storage.len());
self.bitv.storage.grow(newsize, &0);
}
Expand Down Expand Up @@ -881,7 +880,7 @@ impl BitvSet {
fn commons<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
let min = cmp::min(self.bitv.storage.len(), other.bitv.storage.len());
self.bitv.storage.slice(0, min).iter().enumerate()
.zip(Repeat::new(&other.bitv.storage))
.map(|((i, &w), o_store)| (i * uint::BITS, w, o_store[i]))
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! RingBuf implements the trait Deque. It should be imported with `use
//! extra::container::Deque`.

use std::num;
use std::cmp;
use std::vec;
use std::iter::{Rev, RandomAccessIterator};

Expand Down Expand Up @@ -120,7 +120,7 @@ impl<T> RingBuf<T> {
/// Create an empty RingBuf with space for at least `n` elements.
pub fn with_capacity(n: uint) -> RingBuf<T> {
RingBuf{nelts: 0, lo: 0,
elts: vec::from_fn(num::max(MINIMUM_CAPACITY, n), |_| None)}
elts: vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
}

/// Retrieve an element in the RingBuf by index
Expand Down
10 changes: 6 additions & 4 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use time::precise_time_ns;
use collections::TreeMap;

use std::clone::Clone;
use std::cmp;
use std::io;
use std::io::File;
use std::io::Writer;
Expand Down Expand Up @@ -1003,7 +1004,7 @@ impl MetricMap {
if delta.abs() <= noise {
LikelyNoise
} else {
let pct = delta.abs() / (vold.value).max(&f64::EPSILON) * 100.0;
let pct = delta.abs() / cmp::max(vold.value, f64::EPSILON) * 100.0;
if vold.noise < 0.0 {
// When 'noise' is negative, it means we want
// to see deltas that go up over time, and can
Expand Down Expand Up @@ -1126,7 +1127,7 @@ impl BenchHarness {
if self.iterations == 0 {
0
} else {
self.ns_elapsed() / self.iterations.max(&1)
self.ns_elapsed() / cmp::max(self.iterations, 1)
}
}

Expand All @@ -1149,7 +1150,7 @@ impl BenchHarness {
if self.ns_per_iter() == 0 {
n = 1_000_000;
} else {
n = 1_000_000 / self.ns_per_iter().max(&1);
n = 1_000_000 / cmp::max(self.ns_per_iter(), 1);
}
// if the first run took more than 1ms we don't want to just
// be left doing 0 iterations on every loop. The unfortunate
Expand Down Expand Up @@ -1215,6 +1216,7 @@ impl BenchHarness {
}

pub mod bench {
use std::cmp;
use test::{BenchHarness, BenchSamples};

pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
Expand All @@ -1227,7 +1229,7 @@ pub mod bench {

let ns_iter_summ = bs.auto_bench(f);

let ns_iter = (ns_iter_summ.median as u64).max(&1);
let ns_iter = cmp::max(ns_iter_summ.median as u64, 1);
let iter_s = 1_000_000_000 / ns_iter;
let mb_s = (bs.bytes * iter_s) / 1_000_000;

Expand Down
4 changes: 2 additions & 2 deletions src/libglob/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#[license = "MIT/ASL2"];

use std::cell::Cell;
use std::{os, path};
use std::{cmp, os, path};
use std::io::fs;
use std::path::is_sep;

Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
}

let root_len = pat_root.map_or(0u, |p| p.as_vec().len());
let dir_patterns = pattern.slice_from(root_len.min(&pattern.len()))
let dir_patterns = pattern.slice_from(cmp::min(root_len, pattern.len()))
.split_terminator(is_sep).map(|s| Pattern::new(s)).to_owned_vec();

let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec();
Expand Down
56 changes: 10 additions & 46 deletions src/libnum/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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 };
Expand All @@ -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 };
Expand Down Expand Up @@ -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| {
Expand All @@ -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| {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 0 additions & 19 deletions src/libnum/rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use middle::lint;

use d = driver::driver;

use std::cmp;
use std::io;
use std::num;
use std::os;
use std::str;
use std::task;
Expand Down Expand Up @@ -164,7 +164,7 @@ Available lint options:

let mut max_key = 0;
for &(_, name) in lint_dict.iter() {
max_key = num::max(name.len(), max_key);
max_key = cmp::max(name.len(), max_key);
}
fn padded(max: uint, s: &str) -> ~str {
" ".repeat(max - s.len()) + s
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use syntax::attr::AttrMetaMethods;

use std::c_str::ToCStr;
use std::cast;
use std::cmp;
use std::io;
use std::num;
use std::option;
use std::os::consts::{macos, freebsd, linux, android, win32};
use std::str;
Expand Down Expand Up @@ -331,7 +331,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Option<MetadataBlob> {
let vlen = encoder::metadata_encoding_version.len();
debug!("checking {} bytes of metadata-version stamp",
vlen);
let minsz = num::min(vlen, csz);
let minsz = cmp::min(vlen, csz);
let mut version_ok = false;
vec::raw::buf_as_slice(cvbuf, minsz, |buf0| {
version_ok = (buf0 ==
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use middle::typeck::method_map;
use middle::moves;
use util::ppaux::ty_to_str;

use std::cmp;
use std::iter;
use std::num;
use std::vec;
use syntax::ast::*;
use syntax::ast_util::{unguarded_pat, walk_pat};
Expand Down Expand Up @@ -286,7 +286,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
let max_len = m.rev_iter().fold(0, |max_len, r| {
match r[0].node {
PatVec(ref before, _, ref after) => {
num::max(before.len() + after.len(), max_len)
cmp::max(before.len() + after.len(), max_len)
}
_ => max_len
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/cabi_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use middle::trans::context::CrateContext;

use middle::trans::type_::Type;

use std::num;
use std::cmp;
use std::option::{None, Some};

fn align_up_to(off: uint, a: uint) -> uint {
Expand All @@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
1
} else {
let str_tys = ty.field_types();
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
}
}
Array => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/cabi_mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#[allow(non_uppercase_pattern_statics)];

use std::libc::c_uint;
use std::num;
use std::cmp;
use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
use lib::llvm::StructRetAttribute;
use middle::trans::context::CrateContext;
Expand Down Expand Up @@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
1
} else {
let str_tys = ty.field_types();
str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
}
}
Array => {
Expand Down Expand Up @@ -98,7 +98,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> ArgType {
let size = ty_size(ty) * 8;
let mut align = ty_align(ty);

align = num::min(num::max(align, 4), 8);
align = cmp::min(cmp::max(align, 4), 8);
*offset = align_up_to(*offset, align);
*offset += align_up_to(size, align * 8) / 8;

Expand Down
Loading