Crate gsort

Crate gsort 

Source
Expand description

§gsort - High-Performance External Merge Sort

A fast, memory-efficient external merge sort implementation in Rust, compatible with GNU sort.

§Features

  • High Performance: Faster than GNU sort for many workloads
  • Smart Memory Management: Automatic buffer sizing, no temp files for small-medium files
  • Pure In-Memory Fast Path: When no key/unique features are requested, gsort transparently falls back to a Rayon-powered in-memory sort (matching the CLI flags you provide)
  • Multi-threaded: Parallel sorting for large datasets
  • GNU sort Compatible: Drop-in replacement for most use cases

§Quick Example

use gsort::{Config, run_sort};
use clap::Parser;

let config = Config::parse_from(&["gsort", "input.txt"]);
run_sort(config)?;

§Library Usage

For in-memory sorting:

use gsort::{Config, sort_lines};
use clap::Parser;

let lines = vec![
    b"zebra".to_vec(),
    b"apple".to_vec(),
    b"mango".to_vec(),
];

let config = Config::parse_from(&["gsort"]);
let sorted = sort_lines(lines, &config)?;

assert_eq!(sorted[0], b"apple");
assert_eq!(sorted[1], b"mango");
assert_eq!(sorted[2], b"zebra");

Re-exports§

pub use args::Config;
pub use key::KeySpec;
pub use line::Line;
pub use temp::enable_compression;
pub use temp::init_temp_dirs;
pub use temp::TempRun;

Modules§

args
Command-line argument parsing and configuration.
ioext
I/O and external sorting operations.
key
Key specification and extraction for field-based sorting.
line
Line handling and comparison logic.
merge
K-way merge operations for combining sorted runs.
temp
Temporary file management for external sorting.

Functions§

run_sort
Main sort entry point for processing files.
sort_lines
Sort lines in memory and return sorted result.