diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-19 23:03:11 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-21 09:35:18 +1100 |
| commit | 1b1e4caa79077d48c1bf56bf5bfa7bfc83fdf941 (patch) | |
| tree | 932fade0a40ca5fe22eca4c302adadae3df91b4a /src/libextra | |
| parent | 48fedcb36ffdb4248c238a1bfa7a846e6e27cb68 (diff) | |
std::vec: add a sugary .sort() method for plain Ord sorting.
This moves the custom sorting to `.sort_by`.
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/glob.rs | 2 | ||||
| -rw-r--r-- | src/libextra/priority_queue.rs | 8 | ||||
| -rw-r--r-- | src/libextra/stats.rs | 6 | ||||
| -rw-r--r-- | src/libextra/test.rs | 5 |
4 files changed, 12 insertions, 9 deletions
diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index 75795d13991..78651b818fa 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -148,7 +148,7 @@ impl Iterator<Path> for GlobIterator { fn list_dir_sorted(path: &Path) -> ~[Path] { match io::result(|| fs::readdir(path)) { Ok(mut children) => { - children.sort(|p1, p2| p2.filename() <= p1.filename()); + children.sort_by(|p1, p2| p2.filename() <= p1.filename()); children } Err(..) => ~[] diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index d2cace5e6f4..3c1743cfe34 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -231,7 +231,11 @@ mod tests { fn test_top_and_pop() { let data = ~[2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1]; let mut sorted = data.clone(); +<<<<<<< HEAD sorted.sort(|x, y| x.le(y)); +======= + sorted.sort(); +>>>>>>> 9ceda35... std::vec: add a sugary .sort() method for plain Ord sorting. let mut heap = PriorityQueue::from_vec(data); while !heap.is_empty() { assert_eq!(heap.top(), sorted.last()); @@ -314,8 +318,8 @@ mod tests { fn check_to_vec(mut data: ~[int]) { let heap = PriorityQueue::from_vec(data.clone()); let mut v = heap.clone().to_vec(); - v.sort(|x, y| x.le(y)); - data.sort(|x, y| x.le(y)); + v.sort(); + data.sort(); assert_eq!(v, data); assert_eq!(heap.to_sorted_vec(), data); diff --git a/src/libextra/stats.rs b/src/libextra/stats.rs index e4ef5723dd3..ba8f7d4f23f 100644 --- a/src/libextra/stats.rs +++ b/src/libextra/stats.rs @@ -239,13 +239,13 @@ impl<'a> Stats for &'a [f64] { fn percentile(self, pct: f64) -> f64 { let mut tmp = self.to_owned(); - tmp.sort(|a,b| a <= b); + tmp.sort(); percentile_of_sorted(tmp, pct) } fn quartiles(self) -> (f64,f64,f64) { let mut tmp = self.to_owned(); - tmp.sort(|a,b| a <= b); + tmp.sort(); let a = percentile_of_sorted(tmp, 25.0); let b = percentile_of_sorted(tmp, 50.0); let c = percentile_of_sorted(tmp, 75.0); @@ -290,7 +290,7 @@ fn percentile_of_sorted(sorted_samples: &[f64], /// See: http://en.wikipedia.org/wiki/Winsorising pub fn winsorize(samples: &mut [f64], pct: f64) { let mut tmp = samples.to_owned(); - tmp.sort(|a,b| a <= b); + tmp.sort(); let lo = percentile_of_sorted(tmp, pct); let hi = percentile_of_sorted(tmp, 100.0-pct); for samp in samples.mut_iter() { diff --git a/src/libextra/test.rs b/src/libextra/test.rs index af22aad7b5e..dd29a4d8d47 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -37,7 +37,6 @@ use std::to_str::ToStr; use std::f64; use std::os; - // The name of a test. By convention this follows the rules for rust // paths; i.e. it should be a series of identifiers separated by double // colons. This way if some test runner wants to arrange the tests @@ -487,7 +486,7 @@ impl<T: Writer> ConsoleTestState<T> { for f in self.failures.iter() { failures.push(f.name.to_str()); } - failures.sort(|a,b| a <= b); + failures.sort(); for name in failures.iter() { self.write_plain(format!(" {}\n", name.to_str())); } @@ -841,7 +840,7 @@ pub fn filter_tests( fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool { t1.desc.name.to_str() <= t2.desc.name.to_str() } - filtered.sort(lteq); + filtered.sort_by(lteq); // Shard the remaining tests, if sharding requested. match opts.test_shard { |
