GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Yikai-Liao/tessera-order: Stable radix sort with O(√n) auxiliary memory

BranchesTags
Open more actions menu

Latest commit

 

History

311 Commits
311 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
assets
assets
 
 
bench
bench
 
 
conformance
conformance
 
 
docs
docs
 
 
fuzz
fuzz
 
 
rust
rust
 
 
tools
tools
 
 
.agentic-review.md
.agentic-review.md
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
AGENTS.md
AGENTS.md
 
 
CLAUDE.md
CLAUDE.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
RELEASING.md
RELEASING.md
 
 
ROADMAP.md
ROADMAP.md
 
 
SECURITY.md
SECURITY.md
 
 
biome.json
biome.json
 
 
bun.lock
bun.lock
 
 
package.json
package.json
 
 
rustfmt.toml
rustfmt.toml
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

Tessera logo: a mosaic rosette

Tessera

Stable radix ordering with O(√n) auxiliary memory.
One linear-time engine for stable sorting, argsort and single-rank selection, safe for records that own resources.

CI License: BSD-2-Clause MSRV 1.89 crates.io docs.rs Documentation

Note

0.2 adds cached-key sorting, argsort, selection and more key types, and renames the 0.1 sorts; see versions to migrate. 0.x minor releases may change the API; see the roadmap.

Why Tessera

An LSD radix sort is stable and runs in linear time, but it needs a second buffer as large as the input. Comparison sorts avoid that buffer and pay O(n log n) comparisons instead. Tessera keeps the radix sort's linear time and stability and bounds the extra memory to O(√n).

The same engine sorts records, sorts index payloads for argsort, and can skip further work on bands that do not contain the rank requested by select_nth. Cached-key sorting can reuse the engine's stable distribution when the keys differ only in a narrow bit window.

  • Stable, also for descending keys.
  • O(√n) sorting scratch, through a stable in-place block partition and a bounded tile buffer. Cached keys and argsort's index output use O(n) space; parallel sorting uses O(P√n) scratch for P participating threads.
  • Adaptive. Sorted, reverse-sorted, nearly sorted and heavily repeated inputs take shortcuts, and constant key bits are skipped.
  • Any record type. No Copy, Clone, Default or Ord needed. Records are moved, never duplicated, even if the key function misbehaves or panics.
  • Fixed-width keys. Supports fixed-width keys encoded as unsigned integers; see key encoding for supported types and limits.
  • One portable backend. Uses fearless_simd for vector scans and prefix sums, selecting supported instructions automatically. Requires std and Rust 1.89; Rayon is optional.

Quick start

[dependencies]
tessera-order = "0.2"

SIMD is always enabled; there is no portable-simd or std feature. Disabling default features does not change the backend or remove the std requirement.

use std::cmp::Reverse;

let mut values: Vec<u64> = vec![42, 7, 19, 7, 3];
tessera_order::sort(&mut values);
assert_eq!(values, [3, 7, 7, 19, 42]);

// Sort records by a key; equal keys keep their input order.
let mut rows = vec![(2u32, "first"), (1, "middle"), (2, "last")];
tessera_order::sort_by_key(&mut rows, |row| Reverse(row.0));
assert_eq!(rows, [(2, "first"), (2, "last"), (1, "middle")]);

0.1 called the two sorts stable_sort and stable_sort_by_key; 0.2 keeps them as deprecated aliases. Every operation resolves equal keys as a full stable sort would.

API Use
sort(&mut [K]) Sort keys themselves
sort_by_key(&mut [T], F) Sort any records by a key computed by F
sort_by_cached_key(&mut [T], F) Sort by a key computed once per record on nontrivial inputs
select_nth / _by_key Place one ranked record and partition around it
argsort / _by_key Return sorted indices without moving source records

See the guide for examples, multi-field sorting for tuple keys, and versions for what 0.1 names differently and how to migrate from earlier development snapshots.

Tessera does not take a comparator: an arbitrary Ordering cannot be turned into radix digits.

The optional rayon feature adds par_sort and par_sort_by_key (0.1: par_stable_sort and par_stable_sort_by_key), plus par_argsort and par_argsort_by_key. Large inputs partition in the caller's Rayon pool through the shared root engine, while small inputs and one-thread pools use the serial engine. See parallel usage and the parallel contract for record and key-function bounds.

Performance

Track Rust benchmark trends on the public Bencher dashboard. These continuous measurements flag changes to investigate; use the benchmark protocol for paired implementation comparisons and source-change attribution.

The implementation comparison ranks Tessera among other sorts by speed and extra memory. The preview below tracks Tessera alone on main.

Main trend: the geometric mean of each mode's run-time change since the first run on the current runner specification; lower is faster. The interactive page filters cases by type, distribution, length and mode, compares cases over any time range and lists absolute times.

Main performance trend

When to use something else

  • Orders defined by a comparator, strings, or other variable-length keys: use slice::sort_by.
  • Parallel sorting without the optional rayon feature: Tessera is single-threaded.
  • No allocator: Tessera needs O(√n) scratch memory, so it cannot run without alloc (or, in C++, without a heap).

Status by language

Each language package is versioned and released separately (RELEASING.md).

Capability Rust 0.2 C++
Stable sort Implemented Planned
Unstable sort Not in 0.2 Planned
Cached-key sort, argsort and selection Implemented Not planned
128-bit keys Signed and unsigned Planned
Records that own resources or hold &mut Supported Trivially copyable records only (planned)

A Python binding is planned as well; see the roadmap.

Learn more

Topic Document
Ordering, key functions, floats, panics and memory bounds conformance/semantics.md
How the algorithm works, with interactive figures Algorithm explanation
How the engine works docs/design/engine.md
Why user key functions cache bucket IDs Record handling
All documentation Documentation site · Source index

Contributing

Bug reports, benchmark results from other machines, and integration reports are welcome, and so are AI-assisted contributions, as long as a person has reviewed the change and takes responsibility for it. Please read CONTRIBUTING.md first. Commits are signed off under the Developer Certificate of Origin, and everyone in the project follows the code of conduct. Report security issues privately as described in SECURITY.md.

Acknowledgements

The stable block partition is adapted from Robert Clausecker's radixsort_permuted.c, described in Parallel O(√n) Overhead LSD Radix Sort by Robert Clausecker and Florian Schintke. The paper also suggests the hybrid Tessera builds on: splitting on the most significant digit first, then sorting each bucket's remaining digits least significant first.

Tessera was developed and measured with Lukas Bergdoll's sort-research-rs benchmark harness.

License

Tessera is licensed under the BSD 2-Clause License. This covers the code adapted from radixsort_permuted.c, which is distributed under the same license.

About

Stable radix sort with O(√n) auxiliary memory

yikai-liao.github.io/tessera-order/

Topics

radix-sortrustsortingsorting-algorithmsstable-sort

Resources

Readme
BSD-2-Clause license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

4 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.