1
Fork 0

extra: remove sort in favour of the std method.

Fixes #9676.
This commit is contained in:
Huon Wilson 2013-12-19 16:53:02 +11:00
parent 721609e4ae
commit 48fedcb36f
15 changed files with 47 additions and 1247 deletions

View file

@ -28,8 +28,6 @@ use std::io;
use std::io::fs; use std::io::fs;
use std::path::is_sep; use std::path::is_sep;
use sort;
/** /**
* An iterator that yields Paths from the filesystem that match a particular * An iterator that yields Paths from the filesystem that match a particular
* pattern - see the `glob` function for more details. * pattern - see the `glob` function for more details.
@ -149,9 +147,8 @@ impl Iterator<Path> for GlobIterator {
fn list_dir_sorted(path: &Path) -> ~[Path] { fn list_dir_sorted(path: &Path) -> ~[Path] {
match io::result(|| fs::readdir(path)) { match io::result(|| fs::readdir(path)) {
Ok(children) => { Ok(mut children) => {
let mut children = children; children.sort(|p1, p2| p2.filename() <= p1.filename());
sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());
children children
} }
Err(..) => ~[] Err(..) => ~[]
@ -771,4 +768,3 @@ mod test {
assert!(Pattern::new("a/b").matches_path(&Path::new("a/b"))); assert!(Pattern::new("a/b").matches_path(&Path::new("a/b")));
} }
} }

View file

@ -61,8 +61,6 @@ pub mod ringbuf;
pub mod priority_queue; pub mod priority_queue;
pub mod smallintmap; pub mod smallintmap;
pub mod sort;
pub mod dlist; pub mod dlist;
pub mod treemap; pub mod treemap;
pub mod btree; pub mod btree;

View file

@ -213,7 +213,6 @@ impl<T: Ord> Extendable<T> for PriorityQueue<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use sort::merge_sort;
use priority_queue::PriorityQueue; use priority_queue::PriorityQueue;
#[test] #[test]
@ -231,7 +230,8 @@ mod tests {
#[test] #[test]
fn test_top_and_pop() { fn test_top_and_pop() {
let data = ~[2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1]; let data = ~[2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1];
let mut sorted = merge_sort(data, |x, y| x.le(y)); let mut sorted = data.clone();
sorted.sort(|x, y| x.le(y));
let mut heap = PriorityQueue::from_vec(data); let mut heap = PriorityQueue::from_vec(data);
while !heap.is_empty() { while !heap.is_empty() {
assert_eq!(heap.top(), sorted.last()); assert_eq!(heap.top(), sorted.last());
@ -311,11 +311,14 @@ mod tests {
assert_eq!(heap.len(), 5); assert_eq!(heap.len(), 5);
} }
fn check_to_vec(data: ~[int]) { fn check_to_vec(mut data: ~[int]) {
let heap = PriorityQueue::from_vec(data.clone()); let heap = PriorityQueue::from_vec(data.clone());
assert_eq!(merge_sort(heap.clone().to_vec(), |x, y| x.le(y)), let mut v = heap.clone().to_vec();
merge_sort(data, |x, y| x.le(y))); v.sort(|x, y| x.le(y));
assert_eq!(heap.to_sorted_vec(), merge_sort(data, |x, y| x.le(y))); data.sort(|x, y| x.le(y));
assert_eq!(v, data);
assert_eq!(heap.to_sorted_vec(), data);
} }
#[test] #[test]

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,6 @@
#[allow(missing_doc)]; #[allow(missing_doc)];
use sort;
use std::cmp; use std::cmp;
use std::hashmap; use std::hashmap;
use std::io; use std::io;
@ -240,13 +239,13 @@ impl<'a> Stats for &'a [f64] {
fn percentile(self, pct: f64) -> f64 { fn percentile(self, pct: f64) -> f64 {
let mut tmp = self.to_owned(); let mut tmp = self.to_owned();
sort::tim_sort(tmp); tmp.sort(|a,b| a <= b);
percentile_of_sorted(tmp, pct) percentile_of_sorted(tmp, pct)
} }
fn quartiles(self) -> (f64,f64,f64) { fn quartiles(self) -> (f64,f64,f64) {
let mut tmp = self.to_owned(); let mut tmp = self.to_owned();
sort::tim_sort(tmp); tmp.sort(|a,b| a <= b);
let a = percentile_of_sorted(tmp, 25.0); let a = percentile_of_sorted(tmp, 25.0);
let b = percentile_of_sorted(tmp, 50.0); let b = percentile_of_sorted(tmp, 50.0);
let c = percentile_of_sorted(tmp, 75.0); let c = percentile_of_sorted(tmp, 75.0);
@ -291,7 +290,7 @@ fn percentile_of_sorted(sorted_samples: &[f64],
/// See: http://en.wikipedia.org/wiki/Winsorising /// See: http://en.wikipedia.org/wiki/Winsorising
pub fn winsorize(samples: &mut [f64], pct: f64) { pub fn winsorize(samples: &mut [f64], pct: f64) {
let mut tmp = samples.to_owned(); let mut tmp = samples.to_owned();
sort::tim_sort(tmp); tmp.sort(|a,b| a <= b);
let lo = percentile_of_sorted(tmp, pct); let lo = percentile_of_sorted(tmp, pct);
let hi = percentile_of_sorted(tmp, 100.0-pct); let hi = percentile_of_sorted(tmp, 100.0-pct);
for samp in samples.mut_iter() { for samp in samples.mut_iter() {

View file

@ -21,7 +21,6 @@ use getopts::groups;
use json::ToJson; use json::ToJson;
use json; use json;
use serialize::Decodable; use serialize::Decodable;
use sort;
use stats::Stats; use stats::Stats;
use stats; use stats;
use term; use term;
@ -488,7 +487,7 @@ impl<T: Writer> ConsoleTestState<T> {
for f in self.failures.iter() { for f in self.failures.iter() {
failures.push(f.name.to_str()); failures.push(f.name.to_str());
} }
sort::tim_sort(failures); failures.sort(|a,b| a <= b);
for name in failures.iter() { for name in failures.iter() {
self.write_plain(format!(" {}\n", name.to_str())); self.write_plain(format!(" {}\n", name.to_str()));
} }
@ -840,9 +839,9 @@ pub fn filter_tests(
// Sort the tests alphabetically // Sort the tests alphabetically
fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool { fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool {
t1.desc.name.to_str() < t2.desc.name.to_str() t1.desc.name.to_str() <= t2.desc.name.to_str()
} }
sort::quick_sort(filtered, lteq); filtered.sort(lteq);
// Shard the remaining tests, if sharding requested. // Shard the remaining tests, if sharding requested.
match opts.test_shard { match opts.test_shard {

View file

@ -150,7 +150,6 @@ Additional help:
} }
pub fn describe_warnings() { pub fn describe_warnings() {
use extra::sort::Sort;
println(" println("
Available lint options: Available lint options:
-W <foo> Warn about <foo> -W <foo> Warn about <foo>
@ -163,7 +162,7 @@ Available lint options:
let mut lint_dict = lint_dict.move_iter() let mut lint_dict = lint_dict.move_iter()
.map(|(k, v)| (v, k)) .map(|(k, v)| (v, k))
.collect::<~[(lint::LintSpec, &'static str)]>(); .collect::<~[(lint::LintSpec, &'static str)]>();
lint_dict.qsort(); lint_dict.sort(|a,b| a <= b);
let mut max_key = 0; let mut max_key = 0;
for &(_, name) in lint_dict.iter() { for &(_, name) in lint_dict.iter() {

View file

@ -17,7 +17,6 @@ use metadata::cstore;
use metadata::decoder; use metadata::decoder;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use extra;
use syntax::ast; use syntax::ast;
use syntax::parse::token::ident_interner; use syntax::parse::token::ident_interner;
@ -192,14 +191,12 @@ pub fn get_dep_hashes(cstore: &CStore) -> ~[@str] {
}); });
} }
let sorted = extra::sort::merge_sort(result, |a, b| { result.sort(|a, b| (a.name, a.vers, a.hash) <= (b.name, b.vers, b.hash));
(a.name, a.vers, a.hash) <= (b.name, b.vers, b.hash)
});
debug!("sorted:"); debug!("sorted:");
for x in sorted.iter() { for x in result.iter() {
debug!(" hash[{}]: {}", x.name, x.hash); debug!(" hash[{}]: {}", x.name, x.hash);
} }
sorted.map(|ch| ch.hash) result.map(|ch| ch.hash)
} }

View file

@ -30,7 +30,6 @@ use std::util;
use std::vec; use std::vec;
use extra::serialize::Encodable; use extra::serialize::Encodable;
use extra;
use syntax::abi::AbiSet; use syntax::abi::AbiSet;
use syntax::ast::*; use syntax::ast::*;
@ -1532,7 +1531,7 @@ fn encode_crate_deps(ecx: &EncodeContext,
}); });
// Sort by cnum // Sort by cnum
extra::sort::quick_sort(deps, |kv1, kv2| kv1.cnum <= kv2.cnum); deps.sort(|kv1, kv2| kv1.cnum <= kv2.cnum);
// Sanity-check the crate numbers // Sanity-check the crate numbers
let mut expected_cnum = 1; let mut expected_cnum = 1;

View file

@ -21,7 +21,6 @@ use util::ppaux::ty_to_str;
use std::iter; use std::iter;
use std::num; use std::num;
use std::vec; use std::vec;
use extra::sort;
use syntax::ast::*; use syntax::ast::*;
use syntax::ast_util::{unguarded_pat, walk_pat}; use syntax::ast_util::{unguarded_pat, walk_pat};
use syntax::codemap::{Span, dummy_sp, Spanned}; use syntax::codemap::{Span, dummy_sp, Spanned};
@ -454,7 +453,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
ty::ty_unboxed_vec(..) | ty::ty_evec(..) => { ty::ty_unboxed_vec(..) | ty::ty_evec(..) => {
// Find the lengths and slices of all vector patterns. // Find the lengths and slices of all vector patterns.
let vec_pat_lens = m.iter().filter_map(|r| { let mut vec_pat_lens = m.iter().filter_map(|r| {
match r[0].node { match r[0].node {
PatVec(ref before, ref slice, ref after) => { PatVec(ref before, ref slice, ref after) => {
Some((before.len() + after.len(), slice.is_some())) Some((before.len() + after.len(), slice.is_some()))
@ -465,21 +464,19 @@ fn missing_ctor(cx: &MatchCheckCtxt,
// Sort them by length such that for patterns of the same length, // Sort them by length such that for patterns of the same length,
// those with a destructured slice come first. // those with a destructured slice come first.
let mut sorted_vec_lens = sort::merge_sort(vec_pat_lens, vec_pat_lens.sort(|&(len1, slice1), &(len2, slice2)| {
|&(len1, slice1), &(len2, slice2)| {
if len1 == len2 { if len1 == len2 {
slice1 > slice2 slice1 > slice2
} else { } else {
len1 <= len2 len1 <= len2
} }
} });
); vec_pat_lens.dedup();
sorted_vec_lens.dedup();
let mut found_slice = false; let mut found_slice = false;
let mut next = 0; let mut next = 0;
let mut missing = None; let mut missing = None;
for &(length, slice) in sorted_vec_lens.iter() { for &(length, slice) in vec_pat_lens.iter() {
if length != next { if length != next {
missing = Some(next); missing = Some(next);
break; break;

View file

@ -73,7 +73,6 @@ use std::libc::c_uint;
use std::vec; use std::vec;
use std::local_data; use std::local_data;
use extra::time; use extra::time;
use extra::sort;
use syntax::ast::Name; use syntax::ast::Name;
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name}; use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name};
use syntax::ast_util::{local_def, is_local}; use syntax::ast_util::{local_def, is_local};
@ -3163,10 +3162,9 @@ pub fn trans_crate(sess: session::Session,
println!("n_inlines: {}", ccx.stats.n_inlines); println!("n_inlines: {}", ccx.stats.n_inlines);
println!("n_closures: {}", ccx.stats.n_closures); println!("n_closures: {}", ccx.stats.n_closures);
println("fn stats:"); println("fn stats:");
sort::quick_sort(ccx.stats.fn_stats,
|&(_, _, insns_a), &(_, _, insns_b)| { ccx.stats.fn_stats.sort(|&(_, _, insns_a), &(_, _, insns_b)| insns_a >= insns_b);
insns_a > insns_b
});
for tuple in ccx.stats.fn_stats.iter() { for tuple in ccx.stats.fn_stats.iter() {
match *tuple { match *tuple {
(ref name, ms, insns) => { (ref name, ms, insns) => {

View file

@ -45,8 +45,6 @@ use std::vec;
use extra::arc::Arc; use extra::arc::Arc;
use extra::json::ToJson; use extra::json::ToJson;
use extra::sort;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
@ -900,16 +898,16 @@ fn item_module(w: &mut Writer, cx: &Context,
debug!("{:?}", items); debug!("{:?}", items);
let mut indices = vec::from_fn(items.len(), |i| i); let mut indices = vec::from_fn(items.len(), |i| i);
fn lt(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> bool { fn le(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> bool {
if shortty(i1) == shortty(i2) { if shortty(i1) == shortty(i2) {
return i1.name < i2.name; return i1.name <= i2.name;
} }
match (&i1.inner, &i2.inner) { match (&i1.inner, &i2.inner) {
(&clean::ViewItemItem(ref a), &clean::ViewItemItem(ref b)) => { (&clean::ViewItemItem(ref a), &clean::ViewItemItem(ref b)) => {
match (&a.inner, &b.inner) { match (&a.inner, &b.inner) {
(&clean::ExternMod(..), _) => true, (&clean::ExternMod(..), _) => true,
(_, &clean::ExternMod(..)) => false, (_, &clean::ExternMod(..)) => false,
_ => idx1 < idx2, _ => idx1 <= idx2,
} }
} }
(&clean::ViewItemItem(..), _) => true, (&clean::ViewItemItem(..), _) => true,
@ -932,12 +930,12 @@ fn item_module(w: &mut Writer, cx: &Context,
(_, &clean::FunctionItem(..)) => false, (_, &clean::FunctionItem(..)) => false,
(&clean::TypedefItem(..), _) => true, (&clean::TypedefItem(..), _) => true,
(_, &clean::TypedefItem(..)) => false, (_, &clean::TypedefItem(..)) => false,
_ => idx1 < idx2, _ => idx1 <= idx2,
} }
} }
debug!("{:?}", indices); debug!("{:?}", indices);
sort::quick_sort(indices, |&i1, &i2| lt(&items[i1], &items[i2], i1, i2)); indices.sort(|&i1, &i2| le(&items[i1], &items[i2], i1, i2));
debug!("{:?}", indices); debug!("{:?}", indices);
let mut curty = ""; let mut curty = "";
@ -1532,7 +1530,7 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
} }
for (_, items) in map.mut_iter() { for (_, items) in map.mut_iter() {
sort::quick_sort(*items, |i1, i2| i1 < i2); items.sort(|i1, i2| i1 <= i2);
} }
return map; return map;
} }

View file

@ -10,8 +10,6 @@
// Functions dealing with attributes and meta items // Functions dealing with attributes and meta items
use extra;
use ast; use ast;
use ast::{Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList}; use ast::{Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
use codemap::{Span, Spanned, spanned, dummy_spanned}; use codemap::{Span, Spanned, spanned, dummy_spanned};
@ -205,7 +203,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] {
.map(|&mi| (mi.name(), mi)) .map(|&mi| (mi.name(), mi))
.collect::<~[(@str, @MetaItem)]>(); .collect::<~[(@str, @MetaItem)]>();
extra::sort::quick_sort(v, |&(a, _), &(b, _)| a <= b); v.sort(|&(a, _), &(b, _)| a <= b);
// There doesn't seem to be a more optimal way to do this // There doesn't seem to be a more optimal way to do this
v.move_iter().map(|(_, m)| { v.move_iter().map(|(_, m)| {

View file

@ -15,7 +15,6 @@
extern mod extra; extern mod extra;
use extra::sort;
use std::cmp::Ord; use std::cmp::Ord;
use std::comm; use std::comm;
use std::hashmap::HashMap; use std::hashmap::HashMap;
@ -54,8 +53,10 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
} }
// sort by key, then by value // sort by key, then by value
fn sortKV<TT:Clone + Ord, UU:Clone + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] { fn sortKV<TT:Clone + Ord, UU:Clone + Ord>(mut orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val); orig.sort(le_by_key);
orig.sort(le_by_val);
origin
} }
let mut pairs = ~[]; let mut pairs = ~[];

View file

@ -9,7 +9,6 @@ use std::libc::{stat, strlen};
use std::ptr::null; use std::ptr::null;
use std::unstable::intrinsics::init; use std::unstable::intrinsics::init;
use std::vec::{reverse}; use std::vec::{reverse};
use extra::sort::quick_sort3;
static LINE_LEN: uint = 80; static LINE_LEN: uint = 80;
static TABLE: [u8, ..4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ]; static TABLE: [u8, ..4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ];
@ -267,7 +266,7 @@ fn print_frequencies(frequencies: &Table, frame: i32) {
for frequencies.each |entry| { for frequencies.each |entry| {
vector.push((entry.code, entry.count)); vector.push((entry.code, entry.count));
} }
quick_sort3(vector); vector.sort(|a,b| a <= b);
let mut total_count = 0; let mut total_count = 0;
for vector.each |&(_, count)| { for vector.each |&(_, count)| {