parent
721609e4ae
commit
48fedcb36f
@ -28,8 +28,6 @@ use std::io;
|
||||
use std::io::fs;
|
||||
use std::path::is_sep;
|
||||
|
||||
use sort;
|
||||
|
||||
/**
|
||||
* An iterator that yields Paths from the filesystem that match a particular
|
||||
* pattern - see the `glob` function for more details.
|
||||
@ -149,9 +147,8 @@ impl Iterator<Path> for GlobIterator {
|
||||
|
||||
fn list_dir_sorted(path: &Path) -> ~[Path] {
|
||||
match io::result(|| fs::readdir(path)) {
|
||||
Ok(children) => {
|
||||
let mut children = children;
|
||||
sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());
|
||||
Ok(mut children) => {
|
||||
children.sort(|p1, p2| p2.filename() <= p1.filename());
|
||||
children
|
||||
}
|
||||
Err(..) => ~[]
|
||||
@ -771,4 +768,3 @@ mod test {
|
||||
assert!(Pattern::new("a/b").matches_path(&Path::new("a/b")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,6 @@ pub mod ringbuf;
|
||||
pub mod priority_queue;
|
||||
pub mod smallintmap;
|
||||
|
||||
pub mod sort;
|
||||
|
||||
pub mod dlist;
|
||||
pub mod treemap;
|
||||
pub mod btree;
|
||||
|
@ -213,7 +213,6 @@ impl<T: Ord> Extendable<T> for PriorityQueue<T> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sort::merge_sort;
|
||||
use priority_queue::PriorityQueue;
|
||||
|
||||
#[test]
|
||||
@ -231,7 +230,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_top_and_pop() {
|
||||
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);
|
||||
while !heap.is_empty() {
|
||||
assert_eq!(heap.top(), sorted.last());
|
||||
@ -311,11 +311,14 @@ mod tests {
|
||||
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());
|
||||
assert_eq!(merge_sort(heap.clone().to_vec(), |x, y| x.le(y)),
|
||||
merge_sort(data, |x, y| x.le(y)));
|
||||
assert_eq!(heap.to_sorted_vec(), merge_sort(data, |x, y| x.le(y)));
|
||||
let mut v = heap.clone().to_vec();
|
||||
v.sort(|x, y| x.le(y));
|
||||
data.sort(|x, y| x.le(y));
|
||||
|
||||
assert_eq!(v, data);
|
||||
assert_eq!(heap.to_sorted_vec(), data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
1181
src/libextra/sort.rs
1181
src/libextra/sort.rs
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,6 @@
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use sort;
|
||||
use std::cmp;
|
||||
use std::hashmap;
|
||||
use std::io;
|
||||
@ -240,13 +239,13 @@ impl<'a> Stats for &'a [f64] {
|
||||
|
||||
fn percentile(self, pct: f64) -> f64 {
|
||||
let mut tmp = self.to_owned();
|
||||
sort::tim_sort(tmp);
|
||||
tmp.sort(|a,b| a <= b);
|
||||
percentile_of_sorted(tmp, pct)
|
||||
}
|
||||
|
||||
fn quartiles(self) -> (f64,f64,f64) {
|
||||
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 b = percentile_of_sorted(tmp, 50.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
|
||||
pub fn winsorize(samples: &mut [f64], pct: f64) {
|
||||
let mut tmp = samples.to_owned();
|
||||
sort::tim_sort(tmp);
|
||||
tmp.sort(|a,b| a <= b);
|
||||
let lo = percentile_of_sorted(tmp, pct);
|
||||
let hi = percentile_of_sorted(tmp, 100.0-pct);
|
||||
for samp in samples.mut_iter() {
|
||||
|
@ -21,7 +21,6 @@ use getopts::groups;
|
||||
use json::ToJson;
|
||||
use json;
|
||||
use serialize::Decodable;
|
||||
use sort;
|
||||
use stats::Stats;
|
||||
use stats;
|
||||
use term;
|
||||
@ -488,7 +487,7 @@ impl<T: Writer> ConsoleTestState<T> {
|
||||
for f in self.failures.iter() {
|
||||
failures.push(f.name.to_str());
|
||||
}
|
||||
sort::tim_sort(failures);
|
||||
failures.sort(|a,b| a <= b);
|
||||
for name in failures.iter() {
|
||||
self.write_plain(format!(" {}\n", name.to_str()));
|
||||
}
|
||||
@ -840,9 +839,9 @@ pub fn filter_tests(
|
||||
|
||||
// Sort the tests alphabetically
|
||||
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.
|
||||
match opts.test_shard {
|
||||
|
@ -150,7 +150,6 @@ Additional help:
|
||||
}
|
||||
|
||||
pub fn describe_warnings() {
|
||||
use extra::sort::Sort;
|
||||
println("
|
||||
Available lint options:
|
||||
-W <foo> Warn about <foo>
|
||||
@ -163,7 +162,7 @@ Available lint options:
|
||||
let mut lint_dict = lint_dict.move_iter()
|
||||
.map(|(k, v)| (v, k))
|
||||
.collect::<~[(lint::LintSpec, &'static str)]>();
|
||||
lint_dict.qsort();
|
||||
lint_dict.sort(|a,b| a <= b);
|
||||
|
||||
let mut max_key = 0;
|
||||
for &(_, name) in lint_dict.iter() {
|
||||
|
@ -17,7 +17,6 @@ use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
|
||||
use std::hashmap::HashMap;
|
||||
use extra;
|
||||
use syntax::ast;
|
||||
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| {
|
||||
(a.name, a.vers, a.hash) <= (b.name, b.vers, b.hash)
|
||||
});
|
||||
result.sort(|a, b| (a.name, a.vers, a.hash) <= (b.name, b.vers, b.hash));
|
||||
|
||||
debug!("sorted:");
|
||||
for x in sorted.iter() {
|
||||
for x in result.iter() {
|
||||
debug!(" hash[{}]: {}", x.name, x.hash);
|
||||
}
|
||||
|
||||
sorted.map(|ch| ch.hash)
|
||||
result.map(|ch| ch.hash)
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ use std::util;
|
||||
use std::vec;
|
||||
|
||||
use extra::serialize::Encodable;
|
||||
use extra;
|
||||
|
||||
use syntax::abi::AbiSet;
|
||||
use syntax::ast::*;
|
||||
@ -1532,7 +1531,7 @@ fn encode_crate_deps(ecx: &EncodeContext,
|
||||
});
|
||||
|
||||
// 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
|
||||
let mut expected_cnum = 1;
|
||||
|
@ -21,7 +21,6 @@ use util::ppaux::ty_to_str;
|
||||
use std::iter;
|
||||
use std::num;
|
||||
use std::vec;
|
||||
use extra::sort;
|
||||
use syntax::ast::*;
|
||||
use syntax::ast_util::{unguarded_pat, walk_pat};
|
||||
use syntax::codemap::{Span, dummy_sp, Spanned};
|
||||
@ -454,7 +453,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
|
||||
ty::ty_unboxed_vec(..) | ty::ty_evec(..) => {
|
||||
|
||||
// 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 {
|
||||
PatVec(ref before, ref slice, ref after) => {
|
||||
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,
|
||||
// those with a destructured slice come first.
|
||||
let mut sorted_vec_lens = sort::merge_sort(vec_pat_lens,
|
||||
|&(len1, slice1), &(len2, slice2)| {
|
||||
if len1 == len2 {
|
||||
slice1 > slice2
|
||||
} else {
|
||||
len1 <= len2
|
||||
}
|
||||
}
|
||||
);
|
||||
sorted_vec_lens.dedup();
|
||||
vec_pat_lens.sort(|&(len1, slice1), &(len2, slice2)| {
|
||||
if len1 == len2 {
|
||||
slice1 > slice2
|
||||
} else {
|
||||
len1 <= len2
|
||||
}
|
||||
});
|
||||
vec_pat_lens.dedup();
|
||||
|
||||
let mut found_slice = false;
|
||||
let mut next = 0;
|
||||
let mut missing = None;
|
||||
for &(length, slice) in sorted_vec_lens.iter() {
|
||||
for &(length, slice) in vec_pat_lens.iter() {
|
||||
if length != next {
|
||||
missing = Some(next);
|
||||
break;
|
||||
|
@ -73,7 +73,6 @@ use std::libc::c_uint;
|
||||
use std::vec;
|
||||
use std::local_data;
|
||||
use extra::time;
|
||||
use extra::sort;
|
||||
use syntax::ast::Name;
|
||||
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name};
|
||||
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_closures: {}", ccx.stats.n_closures);
|
||||
println("fn stats:");
|
||||
sort::quick_sort(ccx.stats.fn_stats,
|
||||
|&(_, _, insns_a), &(_, _, insns_b)| {
|
||||
insns_a > insns_b
|
||||
});
|
||||
|
||||
ccx.stats.fn_stats.sort(|&(_, _, insns_a), &(_, _, insns_b)| insns_a >= insns_b);
|
||||
|
||||
for tuple in ccx.stats.fn_stats.iter() {
|
||||
match *tuple {
|
||||
(ref name, ms, insns) => {
|
||||
|
@ -45,8 +45,6 @@ use std::vec;
|
||||
|
||||
use extra::arc::Arc;
|
||||
use extra::json::ToJson;
|
||||
use extra::sort;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
|
||||
@ -900,16 +898,16 @@ fn item_module(w: &mut Writer, cx: &Context,
|
||||
debug!("{:?}", items);
|
||||
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) {
|
||||
return i1.name < i2.name;
|
||||
return i1.name <= i2.name;
|
||||
}
|
||||
match (&i1.inner, &i2.inner) {
|
||||
(&clean::ViewItemItem(ref a), &clean::ViewItemItem(ref b)) => {
|
||||
match (&a.inner, &b.inner) {
|
||||
(&clean::ExternMod(..), _) => true,
|
||||
(_, &clean::ExternMod(..)) => false,
|
||||
_ => idx1 < idx2,
|
||||
_ => idx1 <= idx2,
|
||||
}
|
||||
}
|
||||
(&clean::ViewItemItem(..), _) => true,
|
||||
@ -932,12 +930,12 @@ fn item_module(w: &mut Writer, cx: &Context,
|
||||
(_, &clean::FunctionItem(..)) => false,
|
||||
(&clean::TypedefItem(..), _) => true,
|
||||
(_, &clean::TypedefItem(..)) => false,
|
||||
_ => idx1 < idx2,
|
||||
_ => idx1 <= idx2,
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
let mut curty = "";
|
||||
@ -1532,7 +1530,7 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> {
|
||||
}
|
||||
|
||||
for (_, items) in map.mut_iter() {
|
||||
sort::quick_sort(*items, |i1, i2| i1 < i2);
|
||||
items.sort(|i1, i2| i1 <= i2);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
// Functions dealing with attributes and meta items
|
||||
|
||||
use extra;
|
||||
|
||||
use ast;
|
||||
use ast::{Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
|
||||
use codemap::{Span, Spanned, spanned, dummy_spanned};
|
||||
@ -205,7 +203,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> ~[@MetaItem] {
|
||||
.map(|&mi| (mi.name(), mi))
|
||||
.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
|
||||
v.move_iter().map(|(_, m)| {
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
extern mod extra;
|
||||
|
||||
use extra::sort;
|
||||
use std::cmp::Ord;
|
||||
use std::comm;
|
||||
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
|
||||
fn sortKV<TT:Clone + Ord, UU:Clone + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
|
||||
return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val);
|
||||
fn sortKV<TT:Clone + Ord, UU:Clone + Ord>(mut orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
|
||||
orig.sort(le_by_key);
|
||||
orig.sort(le_by_val);
|
||||
origin
|
||||
}
|
||||
|
||||
let mut pairs = ~[];
|
||||
|
@ -9,7 +9,6 @@ use std::libc::{stat, strlen};
|
||||
use std::ptr::null;
|
||||
use std::unstable::intrinsics::init;
|
||||
use std::vec::{reverse};
|
||||
use extra::sort::quick_sort3;
|
||||
|
||||
static LINE_LEN: uint = 80;
|
||||
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| {
|
||||
vector.push((entry.code, entry.count));
|
||||
}
|
||||
quick_sort3(vector);
|
||||
vector.sort(|a,b| a <= b);
|
||||
|
||||
let mut total_count = 0;
|
||||
for vector.each |&(_, count)| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user