Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: notriddle/rust-timsort
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: RustPython/rust-timsort
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 14 commits
  • 20 files changed
  • 4 contributors

Commits on Aug 26, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    fa30272 View commit details

Commits on Aug 27, 2020

  1. Add CI, update license

    coolreader18 committed Aug 27, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    3af08fc View commit details
  2. Update metadata

    coolreader18 committed Aug 27, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    a7f17bf View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    fc9812f View commit details
  4. Move $x/mod.rs to $x.rs

    coolreader18 committed Aug 27, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    3691b1a View commit details
  5. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    fb2eb55 View commit details

Commits on Sep 29, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    415fd12 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    704215c View commit details

Commits on Nov 23, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    7e68722 View commit details

Commits on May 5, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    235bc0c View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    607edb8 View commit details
  3. Make crate no_std

    coolreader18 committed May 5, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    2f41f4a View commit details

Commits on Nov 29, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7c2dcb6 View commit details
  2. 0.1.3

    youknowone committed Nov 29, 2023
    Copy the full SHA
    cbe5c98 View commit details
Showing with 884 additions and 623 deletions.
  1. +30 −0 .github/workflows/ci.yaml
  2. +0 −5 .travis.yml
  3. +7 −3 Cargo.toml
  4. +1 −0 LICENSE-MIT
  5. +41 −29 benches/bench.rs
  6. +40 −28 benches/bench_default.rs
  7. +46 −0 src/find_run.rs
  8. +0 −41 src/find_run/mod.rs
  9. +10 −13 src/find_run/tests.rs
  10. +51 −42 src/{gallop/mod.rs → gallop.rs}
  11. +27 −27 src/gallop/tests.rs
  12. +31 −0 src/insort.rs
  13. +0 −32 src/insort/mod.rs
  14. +19 −20 src/insort/tests.rs
  15. +97 −8 src/lib.rs
  16. +353 −0 src/merge.rs
  17. +0 −249 src/merge/mod.rs
  18. +54 −43 src/merge/tests.rs
  19. +49 −53 src/{sort/mod.rs → sort.rs}
  20. +28 −30 src/sort/tests.rs
30 changes: 30 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
pull_request:
push:
branches: [master]

jobs:
build_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Test (debug)
uses: actions-rs/cargo@v1
with:
command: test
- name: Test (release)
uses: actions-rs/cargo@v1
with:
command: test
args: --release
- name: Check rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
- name: Check clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --tests -- -Dwarnings
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "timsort"
version = "0.1.0"
authors = ["Michael Howell <michael@notriddle.com>"]
version = "0.1.3"
description = "Rust implementation of the modified MergeSort used in Python and Java"
repository = "https://github.com/RustPython/rust-timsort"
authors = ["Michael Howell <michael@notriddle.com>", "RustPython Team"]
license = "MIT/Apache-2.0"
edition = "2018"

[dev-dependencies]
rand = "0.3.9"
rand = { version = "0.8", features = ["small_rng"] }

1 change: 1 addition & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2015 Michael Howell
Portions (c) 2020 RustPython Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
70 changes: 41 additions & 29 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -3,24 +3,26 @@
#![feature(test)]
#![feature(unboxed_closures)]

extern crate timsort;
extern crate test;
extern crate rand;

use timsort::sort;
use rand::{weak_rng, Rng};
use rand::{distributions::Standard, prelude::SmallRng, seq::SliceRandom, Rng, SeedableRng};
use std::mem;
use test::Bencher;
use timsort::sort;

type BigSortable = (u64, u64, u64, u64);

type BigSortable = (u64,u64,u64,u64);
fn rng() -> impl Rng {
SmallRng::from_entropy()
}

macro_rules! bench_random(
($name: ident, $sortfun: ident, $typ: ty, $n: expr) => (
#[bench]
fn $name(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = rng();
b.iter(|| {
let mut v = rng.gen_iter::<$typ>().take($n).collect::<Vec<$typ>>();
let mut v = (&mut rng).sample_iter(Standard).take($n).collect::<Vec<$typ>>();
$sortfun(&mut v[..]);
});
b.bytes = $n * mem::size_of::<$typ>() as u64;
@@ -42,7 +44,7 @@ bench_random!(sort_big_random_large, sort, BigSortable, 10_000);

#[bench]
fn sort_sorted(b: &mut Bencher) {
let mut v: Vec<_> = (0 .. 10000isize).collect();
let mut v: Vec<_> = (0..10000isize).collect();
b.iter(|| {
sort(&mut v[..]);
});
@@ -51,7 +53,7 @@ fn sort_sorted(b: &mut Bencher) {

#[bench]
fn sort_big_sorted(b: &mut Bencher) {
let mut v: Vec<_> = (0 .. 10000usize).map(|i| (i, i, i, i)).collect();
let mut v: Vec<_> = (0..10000usize).map(|i| (i, i, i, i)).collect();
b.iter(|| {
sort(&mut v[..]);
});
@@ -61,14 +63,14 @@ fn sort_big_sorted(b: &mut Bencher) {
#[bench]
fn sort_few_unique(b: &mut Bencher) {
let mut v = Vec::new();
for i in (0u32 .. 10) {
for _ in (0usize .. 100) {
for i in 0u32..10 {
for _ in 0usize..100 {
v.push(i);
}
}
let mut rng = weak_rng();
b.iter(||{
rng.shuffle(&mut v[..]);
let mut rng = rng();
b.iter(|| {
v.shuffle(&mut rng);
sort(&mut v[..]);
});
b.bytes = (v.len() * mem::size_of_val(&v[0])) as u64;
@@ -85,31 +87,41 @@ fn sort_equals(b: &mut Bencher) {

#[bench]
fn sort_huge(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = rng();
let n = 100_000;
let mut v = rng.gen_iter::<i64>().take(n).collect::<Vec<i64>>();
let mut v = (&mut rng)
.sample_iter(Standard)
.take(n)
.collect::<Vec<i64>>();
b.iter(|| {
rng.shuffle(&mut v[..]);
v.shuffle(&mut rng);
sort(&mut v[..]);
});
b.bytes = (n * mem::size_of::<i64>()) as u64;
}

#[bench]
fn sort_partially_sorted(b: &mut Bencher) {
fn partially_sort<T: Ord+::std::fmt::Display>(v: &mut [T]) {
fn partially_sort<T: Ord + ::std::fmt::Display>(v: &mut [T]) {
let s = v.len() / 100;
if s == 0 { return; }
if s == 0 {
return;
}
let mut sorted = true;
for c in v.chunks_mut(s) {
if sorted { sort(&mut c[..]); }
if sorted {
sort(&mut c[..]);
}
sorted = !sorted;
}
}
let mut rng = weak_rng();
let mut rng = rng();
let n = 10_000;
let mut v = rng.gen_iter::<i64>().take(n).collect::<Vec<i64>>();
rng.shuffle(&mut v[..]);
let mut v = (&mut rng)
.sample_iter(Standard)
.take(n)
.collect::<Vec<i64>>();
v.shuffle(&mut rng);
partially_sort(&mut v[..]);
b.iter(|| {
let mut v2 = v.clone();
@@ -120,26 +132,26 @@ fn sort_partially_sorted(b: &mut Bencher) {

#[bench]
fn sort_strings(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = rng();
let n = 10_000usize;
let mut v = Vec::with_capacity(n);
let mut bytes = 0;
for _ in (0 .. n) {
let len = rng.gen_range(0, 60);
for _ in 0..n {
let len = rng.gen_range(0..=60);
bytes += len;
let mut s = String::with_capacity(len);
if len == 0 {
v.push(s);
continue;
}
for _ in (0 .. len) {
s.push(rng.gen_range(b'a', b'z') as char);
for _ in 0..len {
s.push(rng.gen_range(b'a'..=b'z') as char);
}
v.push(s);
}

b.iter(|| {
rng.shuffle(&mut v[..]);
v.shuffle(&mut rng);
sort(&mut v[..]);
});
b.bytes = bytes as u64;
68 changes: 40 additions & 28 deletions benches/bench_default.rs
Original file line number Diff line number Diff line change
@@ -3,28 +3,30 @@
#![feature(test)]
#![feature(unboxed_closures)]

extern crate timsort;
extern crate test;
extern crate rand;

use rand::{weak_rng, Rng};
use rand::{distributions::Standard, rngs::SmallRng, seq::SliceRandom, Rng, SeedableRng};
use std::mem;
use test::Bencher;

fn rng() -> impl Rng {
SmallRng::from_entropy()
}

#[inline]
fn sort<T: Ord>(l: &mut [T]) {
l.sort();
}

type BigSortable = (u64,u64,u64,u64);
type BigSortable = (u64, u64, u64, u64);

macro_rules! bench_random(
($name: ident, $sortfun: ident, $typ: ty, $n: expr) => (
#[bench]
fn $name(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = rng();
b.iter(|| {
let mut v = rng.gen_iter::<$typ>().take($n).collect::<Vec<$typ>>();
let mut v = (&mut rng).sample_iter(Standard).take($n).collect::<Vec<$typ>>();
$sortfun(&mut v[..]);
});
b.bytes = $n * mem::size_of::<$typ>() as u64;
@@ -46,7 +48,7 @@ bench_random!(sort_big_random_large, sort, BigSortable, 10_000);

#[bench]
fn sort_sorted(b: &mut Bencher) {
let mut v: Vec<_> = (0 .. 10000isize).collect();
let mut v: Vec<_> = (0..10000isize).collect();
b.iter(|| {
sort(&mut v[..]);
});
@@ -55,7 +57,7 @@ fn sort_sorted(b: &mut Bencher) {

#[bench]
fn sort_big_sorted(b: &mut Bencher) {
let mut v: Vec<_> = (0 .. 10000usize).map(|i| (i, i, i, i)).collect();
let mut v: Vec<_> = (0..10000usize).map(|i| (i, i, i, i)).collect();
b.iter(|| {
sort(&mut v[..]);
});
@@ -65,14 +67,14 @@ fn sort_big_sorted(b: &mut Bencher) {
#[bench]
fn sort_few_unique(b: &mut Bencher) {
let mut v = Vec::new();
for i in (0u32 .. 10) {
for _ in (0usize .. 100) {
for i in 0u32..10 {
for _ in 0usize..100 {
v.push(i);
}
}
let mut rng = weak_rng();
b.iter(||{
rng.shuffle(&mut v[..]);
let mut rng = rng();
b.iter(|| {
v.shuffle(&mut rng);
sort(&mut v[..]);
});
b.bytes = (v.len() * mem::size_of_val(&v[0])) as u64;
@@ -89,31 +91,41 @@ fn sort_equals(b: &mut Bencher) {

#[bench]
fn sort_huge(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = rng();
let n = 100_000;
let mut v = rng.gen_iter::<i64>().take(n).collect::<Vec<i64>>();
let mut v = (&mut rng)
.sample_iter(Standard)
.take(n)
.collect::<Vec<i64>>();
b.iter(|| {
rng.shuffle(&mut v[..]);
v.shuffle(&mut rng);
sort(&mut v[..]);
});
b.bytes = (n * mem::size_of::<i64>()) as u64;
}

#[bench]
fn sort_partially_sorted(b: &mut Bencher) {
fn partially_sort<T: Ord+::std::fmt::Display>(v: &mut [T]) {
fn partially_sort<T: Ord + ::std::fmt::Display>(v: &mut [T]) {
let s = v.len() / 100;
if s == 0 { return; }
if s == 0 {
return;
}
let mut sorted = true;
for c in v.chunks_mut(s) {
if sorted { sort(&mut c[..]); }
if sorted {
sort(&mut c[..]);
}
sorted = !sorted;
}
}
let mut rng = weak_rng();
let mut rng = rng();
let n = 10_000;
let mut v = rng.gen_iter::<i64>().take(n).collect::<Vec<i64>>();
rng.shuffle(&mut v[..]);
let mut v = (&mut rng)
.sample_iter(Standard)
.take(n)
.collect::<Vec<i64>>();
v.shuffle(&mut rng);
partially_sort(&mut v[..]);
b.iter(|| {
let mut v2 = v.clone();
@@ -124,26 +136,26 @@ fn sort_partially_sorted(b: &mut Bencher) {

#[bench]
fn sort_strings(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = rng();
let n = 10_000usize;
let mut v = Vec::with_capacity(n);
let mut bytes = 0;
for _ in (0 .. n) {
let len = rng.gen_range(0, 60);
for _ in 0..n {
let len = rng.gen_range(0..=60);
bytes += len;
let mut s = String::with_capacity(len);
if len == 0 {
v.push(s);
continue;
}
for _ in (0 .. len) {
s.push(rng.gen_range(b'a', b'z') as char);
for _ in 0..len {
s.push(rng.gen_range(b'a'..=b'z') as char);
}
v.push(s);
}

b.iter(|| {
rng.shuffle(&mut v[..]);
v.shuffle(&mut rng);
sort(&mut v[..]);
});
b.bytes = bytes as u64;
Loading