ext_sort/
lib.rs

1//! `ext-sort` is a rust external sort algorithm implementation.
2//!
3//! External sorting is a class of sorting algorithms that can handle massive amounts of data. External sorting
4//! is required when the data being sorted do not fit into the main memory (RAM) of a computer and instead must be
5//! resided in slower external memory, usually a hard disk drive. Sorting is achieved in two passes. During the
6//! first pass it sorts chunks of data that each fit in RAM, during the second pass it merges the sorted chunks
7//! together. For more information see [External Sorting](https://en.wikipedia.org/wiki/External_sorting).
8//!
9//! # Overview
10//!
11//! `ext-sort` supports the following features:
12//!
13//! * **Data agnostic:**
14//!   it supports all data types that implement `serde` serialization/deserialization by default,
15//!   otherwise you can implement your own serialization/deserialization mechanism.
16//! * **Serialization format agnostic:**
17//!   the library uses `MessagePack` serialization format by default, but it can be easily substituted by your custom
18//!   one if `MessagePack` serialization/deserialization performance is not sufficient for your task.
19//! * **Multithreading support:**
20//!   multi-threaded sorting is supported, which means data is sorted in multiple threads utilizing maximum CPU
21//!   resources and reducing sorting time.
22//! * **Memory limit support:**
23//!   memory limited sorting is supported. It allows you to limit sorting memory consumption
24//!   (`memory-limit` feature required).
25//!
26//! # Example
27//!
28//! ```no_run
29//! use std::fs;
30//! use std::io::{self, prelude::*};
31//! use std::path;
32//!
33//! use bytesize::MB;
34//! use env_logger;
35//! use log;
36//!
37//! use ext_sort::{buffer::mem::MemoryLimitedBufferBuilder, ExternalSorter, ExternalSorterBuilder};
38//!
39//! fn main() {
40//!     env_logger::Builder::new().filter_level(log::LevelFilter::Debug).init();
41//!
42//!     let input_reader = io::BufReader::new(fs::File::open("input.txt").unwrap());
43//!     let mut output_writer = io::BufWriter::new(fs::File::create("output.txt").unwrap());
44//!
45//!     let sorter: ExternalSorter<String, io::Error, MemoryLimitedBufferBuilder> = ExternalSorterBuilder::new()
46//!         .with_tmp_dir(path::Path::new("./"))
47//!         .with_buffer(MemoryLimitedBufferBuilder::new(50 * MB))
48//!         .build()
49//!         .unwrap();
50//!
51//!     let sorted = sorter.sort(input_reader.lines()).unwrap();
52//!
53//!     for item in sorted.map(Result::unwrap) {
54//!         output_writer.write_all(format!("{}\n", item).as_bytes()).unwrap();
55//!     }
56//!     output_writer.flush().unwrap();
57//! }
58//! ```
59
60pub mod buffer;
61pub mod chunk;
62pub mod merger;
63pub mod sort;
64
65pub use buffer::{ChunkBuffer, ChunkBufferBuilder, LimitedBuffer, LimitedBufferBuilder};
66pub use chunk::{ExternalChunk, RmpExternalChunk};
67pub use merger::BinaryHeapMerger;
68pub use sort::{ExternalSorter, ExternalSorterBuilder, SortError};