MCPcopy Index your code
hub / github.com/Voultapher/sort-research-rs

github.com/Voultapher/sort-research-rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
1,911 symbols 4,498 edges 194 files 213 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sort-research-rs

  • Is a sort implementation correct?
  • Is a sort implementation fast?

This repository contains:

  • An exhaustive test suite, including properties not commonly checked or upheld
  • An extensive benchmark suite, abstracting over types, patterns and sizes
  • A fuzzing harness
  • A novel sort implementation ipnsort (Instruction-Parallel-Network-Sort)
  • Vendored sort implementations (Rust, C++, C), e.g. cpp_pdqsort, rust_std_stable
  • Various experiments and demonstrations
  • Results of the research as papers

Most tests and benchmarks can be applied to non Rust implementations. This works by implementing the 5 benchmark types as #[repr(C)] and having a defined C API that can be implemented, wrapping the C/C++ sorts.

Most functionality is by default disabled via cargo features, see the Cargo.toml. Some functionality can be enabled or switched by setting environment variables. See for example benches/bench.rs.

Research results

Running the tests

cargo test

cargo miri test

# Might require disabling criterion dependency.
RUSTFLAGS=-Zsanitizer=address cargo t --release

Running the benchmarks

cargo bench

cargo bench <sort_name>-<prediction_state>-<type>-<pattern>-<size>

# Example
cargo bench rust_std_stable-hot-u64-random-10000
cargo bench hot-u64-random-10000
cargo bench random

You can also set a custom regex to filter the benchmarks you want to run:

BENCH_REGEX="std.*i32-random-8$" cargo bench

If you want to collect a set of results that can then later be used to create graphs, you can use the run_benchmarks.py utility script:

# Will write results to my_test_zen3.json
BENCH_REGEX="_stable.*random-" python util/run_benchmarks.py my_test_zen3

To run the graph_all.py script to create graphs from this data you need to first install the dependencies as specified in requirements.txt e.g. on Linux:

python -m venv venv
source ./venv/bin/active
pip install --requirement util/graph_bench_result/requirements.txt

Afterwards, you can use the graph_all.py script:

python util/graph_bench_result/graph_all.py my_test_zen3.json

Fuzzing

You'll need to install cargo fuzz and cargo afl respectively. See https://rust-fuzz.github.io/book/introduction.html.

Fuzzing with libfuzzer

cd fuzz
cargo fuzz run libfuzzer_main

Fuzzing with afl

cd fuzz-afl
RUSTFLAGS=-Zsanitizer=address cargo afl build --release && cargo afl fuzz -i in -o out -D target/release/afl

Adjust fuzz/fuzz_targets/libfuzzer_main.rs and fuzz/fuzz_targets/libfuzzer_main.rs respectively to change the fuzz target. Default rust_ipn_stable.

Contributing

Please respect the CODE_OF_CONDUCT.md when contributing.

Adding a new sort implementation

Please open an issue before investing the effort of adding a new sort implementation. The maintainer of this project is currently not interested in building an up-to-date database of all existing sort implementations. Implementations are added based on situational context and relevance to the maintainers' goals. Baseline for all new sort implementations is they must pass all functionality tests, they may pass the safety tests but don't have to.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE.md file for details.

Extension points exported contracts — how you extend this code

Freeze (Interface)
Can the type have interior mutability, this is checked by testing if T is Freeze. If the type can have interior mutabili [6 …
ipnsort/src/lib.rs
Freeze (Interface)
Can the type have interior mutability, this is checked by testing if T is Freeze. If the type can have interior mutabili [6 …
src/other/partition/hybrid_bitset_partition.rs
StableSortTypeImpl (Interface)
Use a trait to focus code-gen on only the parts actually relevant for the type. Avoid generating LLVM-IR for the stable [2 …
src/graveyard/ipn_stable_with_probe_common.rs
Sortable (Interface)
Creates a trait alias Sortable to combine the requirement for Ordered and Copyable values, into a single Trait. NOTE: Tr [1 …
src/stable/rust_grailsort.rs
Sort (Interface)
(no doc) [3 implementers]
util/rustc-sort-bench/src/evaluate.rs
Sort (Interface)
(no doc) [2 implementers]
sort_test_tools/src/lib.rs
Crumsort (Interface)
(no doc) [2 implementers]
src/unstable/rust_crumsort_rs.rs
UnstableSmallSortTypeImpl (Interface)
Using a trait allows us to specialize on `Freeze` which in turn allows us to make safe abstractions. [2 implementers]
ipnsort/src/smallsort.rs

Core symbols most depended-on inside this repo

len
called by 295
util/rustc-sort-bench/src/benchmark.rs
swap_if_less
called by 280
src/graveyard/ipn_stable_quicksort.rs
instantiate_test_sort
called by 256
util/compile_time_impact/src/main.rs
swap_if_less
called by 214
src/graveyard/rust_new_unstable_04_11_2022.rs
len
called by 210
src/cpp/idisort/qsort_data.h
sub
called by 118
util/rustc-sort-bench/src/measure.rs
len
called by 95
src/graveyard/rust_ipn.rs
swap
called by 78
src/cpp/idisort/qsort_data.h

Shape

Function 1,323
Class 368
Method 181
Interface 34
Enum 5

Languages

Rust77%
C++16%
Python7%
Go1%

Modules by API surface

util/compile_time_impact/src/main.rs515 symbols
src/graveyard/ipn_stable_with_probe_common.rs52 symbols
src/graveyard/graveyard.rs50 symbols
src/stable/rust_grailsort.rs48 symbols
src/graveyard/rust_ipn.rs48 symbols
sort_test_tools/src/tests.rs44 symbols
src/graveyard/ipn_stable_quicksort.rs43 symbols
src/graveyard/rust_new_unstable_04_11_2022.rs39 symbols
util/animation/lomcyc_partition/scene.py33 symbols
src/cpp/shared.h32 symbols
src/other/sort_evolution/stable/timsort_evo4.rs30 symbols
sort_test_tools/src/patterns.rs27 symbols

For agents

$ claude mcp add sort-research-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact