Skip to content

Add a sort method to &mut [T] #11064

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 5 commits into from
Dec 22, 2013
Merged
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
8 changes: 2 additions & 6 deletions src/libextra/glob.rs
Original file line number Diff line number Diff line change
@@ -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_by(|p1, p2| p2.filename().cmp(&p1.filename()));
children
}
Err(..) => ~[]
@@ -771,4 +768,3 @@ mod test {
assert!(Pattern::new("a/b").matches_path(&Path::new("a/b")));
}
}

2 changes: 0 additions & 2 deletions src/libextra/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 9 additions & 6 deletions src/libextra/priority_queue.rs
Original file line number Diff line number Diff line change
@@ -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();
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();
data.sort();

assert_eq!(v, data);
assert_eq!(heap.to_sorted_vec(), data);
}

#[test]
Loading