Skip to content

Commit 8324121

Browse files
authored
Merge pull request #1 from dapper91/dev
Dev
2 parents d63cd37 + 9e7ce50 commit 8324121

File tree

12 files changed

+1072
-0
lines changed

12 files changed

+1072
-0
lines changed

.github/workflows/release.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: release
2+
3+
on:
4+
release:
5+
types:
6+
- released
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Install Rust
14+
run: rustup update stable
15+
- name: Build and publish
16+
run: |
17+
cargo login ${{ secrets.CRATESIO_TOKEN }}
18+
cargo publish

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- dev
7+
- master
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
test:
14+
name: Run unit-tests
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Install Rust
19+
run: rustup update stable
20+
- name: Run tests
21+
run: cargo test --all-features

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
.idea

Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "ext-sort"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "Unlicense"
6+
description = "rust external sort algorithm implementation"
7+
readme = "README.md"
8+
9+
homepage = "https://github.com/dapper91/ext-sort-rs"
10+
documentation = "https://docs.rs/ext-sort/"
11+
repository = "https://github.com/dapper91/ext-sort-rs"
12+
13+
categories = ["algorithms"]
14+
keywords = ["algorithms", "sort", "sorting", "external-sort", "external"]
15+
16+
[dependencies]
17+
bytesize = { version = "^1.1", optional = true }
18+
deepsize = { version = "^0.2", optional = true }
19+
env_logger = { version = "^0.9", optional = true}
20+
log = "0.4"
21+
rayon = "^1.5"
22+
rmp-serde = "^0.15"
23+
serde = { version = "^1.0", features = ["derive"] }
24+
tempfile = "^3.2"
25+
26+
[dev-dependencies]
27+
rstest = "^0.12"
28+
rand = "^0.8"
29+
30+
[features]
31+
memory-limit = ["deepsize"]
32+
33+
[[example]]
34+
name = "quickstart"
35+
required-features = ["bytesize", "env_logger"]

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Rust external sort
2+
3+
`ext-sort` is a rust external sort algorithm implementation.
4+
5+
External sort algorithm implementation. External sorting is a class of sorting algorithms
6+
that can handle massive amounts of data. External sorting is required when the data being
7+
sorted do not fit into the main memory (RAM) of a computer and instead must be resided in
8+
slower external memory, usually a hard disk drive. Sorting is achieved in two passes.
9+
During the first pass it sorts chunks of data that each fit in RAM, during the second pass
10+
it merges the sorted chunks together.
11+
For more information see https://en.wikipedia.org/wiki/External_sorting.
12+
13+
## Features
14+
15+
* **Data agnostic:**
16+
`ext-sort` support all data types that that implement `serde` serialization/deserialization.
17+
* **Serialization format agnostic:**
18+
`ext-sort` use `MessagePack` serialization format by default, but it can be easily substituted by your custom one
19+
if `MessagePack` serialization/deserialization performance is not sufficient for your task.
20+
* **Multithreading support:**
21+
`ext-sort` support multithreading, which means data is sorted in multiple threads utilizing maximum CPU resources
22+
and reducing sorting time.
23+
24+
# Basic example
25+
26+
``` rust
27+
use std::fs;
28+
use std::io::{self, prelude::*};
29+
use std::path;
30+
31+
use bytesize::MB;
32+
use env_logger;
33+
use log;
34+
35+
use ext_sort::buffer::mem::MemoryLimitedBufferBuilder;
36+
use ext_sort::{ExternalSorter, ExternalSorterBuilder};
37+
38+
fn main() {
39+
env_logger::Builder::new().filter_level(log::LevelFilter::Debug).init();
40+
41+
let input_reader = io::BufReader::new(fs::File::open("input.txt").unwrap());
42+
let mut output_writer = io::BufWriter::new(fs::File::create("output.txt").unwrap());
43+
44+
let sorter: ExternalSorter<String, io::Error, MemoryLimitedBufferBuilder> = ExternalSorterBuilder::new()
45+
.with_tmp_dir(path::Path::new("tmp"))
46+
.with_buffer(MemoryLimitedBufferBuilder::new(50 * MB))
47+
.build()
48+
.unwrap();
49+
50+
let sorted = sorter.sort(input_reader.lines()).unwrap();
51+
52+
for item in sorted.map(Result::unwrap) {
53+
output_writer.write_all(format!("{}\n", item).as_bytes()).unwrap();
54+
}
55+
output_writer.flush().unwrap();
56+
}
57+
```

examples/quickstart.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::fs;
2+
use std::io::{self, prelude::*};
3+
use std::path;
4+
5+
use bytesize::MB;
6+
use env_logger;
7+
use log;
8+
9+
use ext_sort::buffer::mem::MemoryLimitedBufferBuilder;
10+
use ext_sort::{ExternalSorter, ExternalSorterBuilder};
11+
12+
fn main() {
13+
env_logger::Builder::new().filter_level(log::LevelFilter::Debug).init();
14+
15+
let input_reader = io::BufReader::new(fs::File::open("input.txt").unwrap());
16+
let mut output_writer = io::BufWriter::new(fs::File::create("output.txt").unwrap());
17+
18+
let sorter: ExternalSorter<String, io::Error, MemoryLimitedBufferBuilder> = ExternalSorterBuilder::new()
19+
.with_tmp_dir(path::Path::new("tmp"))
20+
.with_buffer(MemoryLimitedBufferBuilder::new(50 * MB))
21+
.build()
22+
.unwrap();
23+
24+
let sorted = sorter.sort(input_reader.lines()).unwrap();
25+
26+
for item in sorted.map(Result::unwrap) {
27+
output_writer.write_all(format!("{}\n", item).as_bytes()).unwrap();
28+
}
29+
output_writer.flush().unwrap();
30+
}

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
edition = "2018"
2+
max_width = 120

0 commit comments

Comments
 (0)