Skip to main content

Crate tilo_sort

Crate tilo_sort 

Source
Expand description

Stable slice sorting compiled once for every call site.

std’s sort_by and its relatives are generic over the comparator, so every call site compiles its own copy of the whole sort (several kilobytes each in a release build); in the web desktop’s start module those copies came to about half a megabyte.

CompactSort sorts with one shared, non-generic merge sort over indices: each call site adds only its comparator and a small in-place permutation for its element type. It is stable, O(n log n), and allocates two index vectors, which suits the short lists of interface and model code; keep std’s sorts for large, hot data.

A list ranked by how often and how lately a person chose its entries orders them by Frecency.

use tilo_sort::CompactSort as _;

let mut words = vec!["pear", "fig", "apple", "kiwi"];
words.compact_sort_by_key(|word| word.len());
assert_eq!(words, ["fig", "pear", "kiwi", "apple"]);

Structs§

Frecency
What was chosen how often and when, by an id the caller picks (a package id, an action id). Time is passed in as seconds since the epoch, so the ranking is testable without a clock.

Traits§

CompactSort

Functions§

frecency
How strongly something chosen count times, the last at last, pulls at now (both seconds since the epoch): more choices pull harder, and the pull halves every two weeks after the last. Zero for something never chosen.