| Crates.io | ext-sort |
| lib.rs | ext-sort |
| version | 0.1.5 |
| created_at | 2022-01-08 17:45:40.305855+00 |
| updated_at | 2025-05-09 17:34:04.441504+00 |
| description | rust external sort algorithm implementation |
| homepage | https://github.com/dapper91/ext-sort-rs |
| repository | https://github.com/dapper91/ext-sort-rs |
| max_upload_size | |
| id | 510363 |
| size | 76,429 |
ext-sort is a rust external sort algorithm implementation.
External sorting is a class of sorting algorithms that can handle massive amounts of data. External sorting is required when the data being sorted do not fit into the main memory (RAM) of a computer and instead must be resided in slower external memory, usually a hard disk drive. Sorting is achieved in two passes. During the first pass it sorts chunks of data that each fit in RAM, during the second pass it merges the sorted chunks together. For more information see External Sorting.
ext-sort supports the following features:
serde serialization/deserialization by default,
otherwise you can implement your own serialization/deserialization mechanism.MessagePack serialization format by default, but it can be easily substituted by your custom one
if MessagePack serialization/deserialization performance is not sufficient for your task.memory-limit feature required).Activate memory-limit feature of the ext-sort crate on Cargo.toml:
[dependencies]
ext-sort = { version = "^0.1.5", features = ["memory-limit"] }
use std::fs;
use std::io::{self, prelude::*};
use std::path;
use bytesize::MB;
use env_logger;
use log;
use ext_sort::{buffer::mem::MemoryLimitedBufferBuilder, ExternalSorter, ExternalSorterBuilder};
fn main() {
env_logger::Builder::new().filter_level(log::LevelFilter::Debug).init();
let input_reader = io::BufReader::new(fs::File::open("input.txt").unwrap());
let mut output_writer = io::BufWriter::new(fs::File::create("output.txt").unwrap());
let sorter: ExternalSorter<String, io::Error, MemoryLimitedBufferBuilder> = ExternalSorterBuilder::new()
.with_tmp_dir(path::Path::new("./"))
.with_buffer(MemoryLimitedBufferBuilder::new(50 * MB))
.build()
.unwrap();
let sorted = sorter.sort(input_reader.lines()).unwrap();
for item in sorted.map(Result::unwrap) {
output_writer.write_all(format!("{}\n", item).as_bytes()).unwrap();
}
output_writer.flush().unwrap();
}