A stable, linearithmic sort in constant space written in Rust

Overview

A stable, linearithmic sort in constant space written in Rust. Uses the method described in "Fast Stable Merging And Sorting In Constant Extra Space" by Bing-chao Huang and Michael A. Langston. Heavily inspired by (and named in honor of) Andrey Astrelin's grailsort. Documented in more detail in this blog post.

TODO

This implementation needs some work before it's complete. Here are a few possible improvements (most of them suggested by the folks behind the HolyGrailSort project).

Optimizations:

  • Use MᴇʀɢᴇBᴜғRɪɢʜᴛ (working from right to left) for the last step in Phase 1.
  • IMPORTANT During Phase 2, alternate between a mirrored version of the algorithm and the current version to avoid needing to rotate the internal buffer back to the start of the array at each step.
    • Another alternative (Kotasort?) is to swap the internal buffer into place, then fix up the swapped block's position during BʟᴏᴄᴋRᴏʟʟ.
  • Faster sorting algorithm to prepare the movement imitation buffer:
    • Shell sort
    • Quick sort
    • Linear-time "deinterleave"
      • Relies on the fact that BʟᴏᴄᴋRᴏʟʟ does not change the relative order of A and B blocks; it merely interleves them.
      • This interleaving can be undone in linear time since we know the median element in the movement imitation buffer.
      • Not valid for Phase 2 with a the inline block-taggging scheme, since the movement imitation buffer is repurposed as the internal buffer for MᴇʀɢᴇBᴜғ. Would work for Phase 3, though.
  • Adaptive merging.
  • Faster MᴇʀɢᴇBᴜғ implementation (especially for Phase 2).
    • Current version is a "tape" merge.
    • Could also use a "simple binary" merge: Do an exponential search at each step and swap in batches.
    • Hwang-Lin, a happy medium between the two.
  • Make use small allocations (e.g., big enough for the auxiliary buffer but less than N/2).

Features:

  • Visualize with ArrayV (or something else that interoperates with Rust).
  • Parametric benchmarking:
    • Element size
    • Comparison cost
    • Number of distinct elements
You might also like...
RustFFT is a high-performance FFT library written in pure Rust.

RustFFT is a high-performance FFT library written in pure Rust. It can compute FFTs of any size, including prime-number sizes, in O(nlogn) time.

l2 is a fast, Pytorch-style Tensor+Autograd library written in Rust
l2 is a fast, Pytorch-style Tensor+Autograd library written in Rust

l2 • 🤖 A Pytorch-style Tensor+Autograd library written in Rust Installation • Contributing • Authors • License • Acknowledgements Made by Bilal Khan

Reinforcement learning library written in Rust

REnforce Reinforcement library written in Rust This library is still in early stages, and the API has not yet been finalized. The documentation can be

Barnes-Hut t-SNE implementation written in Rust.
Barnes-Hut t-SNE implementation written in Rust.

bhtsne Barnes-Hut implementation of t-SNE written in Rust. The algorithm is described with fine detail in this paper by Laurens van der Maaten. Instal

A Machine Learning Framework for High Performance written in Rust
A Machine Learning Framework for High Performance written in Rust

polarlight polarlight is a machine learning framework for high performance written in Rust. Key Features TBA Quick Start TBA How To Contribute Contrib

🚀  efficient approximate nearest neighbor search algorithm collections library written in Rust 🦀 .
🚀 efficient approximate nearest neighbor search algorithm collections library written in Rust 🦀 .

🚀 efficient approximate nearest neighbor search algorithm collections library written in Rust 🦀 .

miniature: a toy deep learning library written in Rust

miniature: a toy deep learning library written in Rust A miniature is a toy deep learning library written in Rust. The miniature is: implemented for a

Generic k-means implementation written in Rust

RKM - Rust k-means A simple Rust implementation of the k-means clustering algorithm based on a C++ implementation, dkm. This implementation is generic

A naive density-based clustering algorithm written in Rust
A naive density-based clustering algorithm written in Rust

Density-based clustering This a pure Rust implementation of a naive density-based clustering algorithm similar to DBSCAN. Here, 50 points are located

Comments
  • Great work; further improvements you may be interested in...

    Great work; further improvements you may be interested in...

    Hi, I'm the lead contributor of the Rewritten Grailsort repo!!

    Thank you so much for all your work; your blog post instantly hooked me and was a great read. Gives us more motivation to finish the documentation we were working on yet took a pause from.

    What we have been working on recently is something that might be of interest to you because it greatly reduces the complexity (time, not code! :wink:) of Grail/Mrrlsort: https://github.com/HolyGrailSortProject/Holy-Grailsort

    Let us know your thoughts and feel feel to join our Discord community if you havw any questions! You are more than welcome.

    opened by MusicTheorist 0
Owner
Dylan MacKenzie
Dylan MacKenzie
Stable Diffusion v1.4 ported to Rust's burn framework

Stable-Diffusion-Burn Stable-Diffusion-Burn is a Rust-based project which ports the V1 stable diffusion model into the deep learning framework, Burn.

null 156 Aug 8, 2023
Stable Diffusion XL ported to Rust's burn framework

Stable-Diffusion-XL-Burn Stable-Diffusion-XL-Burn is a Rust-based project which ports stable diffusion xl into the Rust deep learning framework burn.

null 194 Sep 4, 2023
An 8080 Space Invaders emulator in Rust

Space Invade.rs An 8080 Space Invaders emulator written in Rust This is an 8080 emulator running the 1978 Space Invaders game by Taito, written in Rus

Cedric Beust 23 Dec 27, 2022
Rust implementation of multi-index hashing for neighbor searches on binary codes in the Hamming space

mih-rs Rust implementation of multi-index hashing (MIH) for neighbor searches on binary codes in the Hamming space, described in the paper Norouzi, Pu

Shunsuke Kanda 8 Sep 23, 2022
TopK algorithm implementation in Rust (Filtered Space-Saving)

TopK TopK algorithm implementation in Rust. This crate currently provides the Filtered Space-Saving algorithm. Version numbers follow the semver conve

null 6 Feb 24, 2023
Cleora AI is a general-purpose model for efficient, scalable learning of stable and inductive entity embeddings for heterogeneous relational data.

Cleora Cleora is a genus of moths in the family Geometridae. Their scientific name derives from the Ancient Greek geo γῆ or γαῖα "the earth", and metr

Synerise 405 Dec 20, 2022
Hamming Weight Tree from the paper Online Nearest Neighbor Search in Hamming Space

hwt Hamming Weight Tree from the paper Online Nearest Neighbor Search in Hamming Space To understand how the data structure works, please see the docs

Rust Computer Vision 7 Oct 9, 2021
Msgpack serialization/deserialization library for Python, written in Rust using PyO3, and rust-msgpack. Reboot of orjson. msgpack.org[Python]

ormsgpack ormsgpack is a fast msgpack library for Python. It is a fork/reboot of orjson It serializes faster than msgpack-python and deserializes a bi

Aviram Hassan 139 Dec 30, 2022
Fwumious Wabbit, fast on-line machine learning toolkit written in Rust

Fwumious Wabbit is a very fast machine learning tool built with Rust inspired by and partially compatible with Vowpal Wabbit (much love! read more abo

Outbrain 115 Dec 9, 2022
Simple neural network library for classification written in Rust.

Cogent A note I continue working on GPU stuff, I've made some interesting things there, but ultimately it made me realise this is far too monumental a

Jonathan Woollett-Light 41 Dec 25, 2022