reed-solomon-16
A library for Reed-Solomon GF(2^16)
erasure coding, featuring:
O(n log n)
complexity.- Any combination of 1 - 32768 original shards with 1 - 32768 recovery shards.
- Up to 65535 original or recovery shards with some limitations.
- SIMD optimizations are planned, but not yet implemented.
Simple usage
- Divide data into equal-sized original shards. Shard size must be multiple of 64 bytes.
- Decide how many recovery shards you want.
- Generate recovery shards with
reed_solomon_16::encode
. - When some original shards get lost, restore them with
reed_solomon_16::decode
.- You must provide at least as many shards as there were original shards in total, in any combination of original shards and recovery shards.
Example
Divide data into 3 original shards of 64 bytes each and generate 5 recovery shards. Assume then that original shards #0 and #2 are lost and restore them by providing 1 original shard and 2 recovery shards.
let original = ;
let recovery = encode?;
let restored = decode?;
assert_eq!;
assert_eq!;
# Ok::
Basic usage
ReedSolomonEncoder
and ReedSolomonDecoder
give more control
of the encoding/decoding process.
Here's the above example using these instead:
use ;
use HashMap;
let original = ;
let mut encoder = new?;
for original in original
let result = encoder.encode?;
let recovery: = result.recovery_iter.collect;
let mut decoder = new?;
decoder.add_original_shard?;
decoder.add_recovery_shard?;
decoder.add_recovery_shard?;
let result = decoder.decode?;
let restored: = result.restored_original_iter.collect;
assert_eq!;
assert_eq!;
# Ok::
Advanced usage
See rate
module for advanced encoding/decoding
using chosen Engine
and Rate
.
Benchmarks
- These benchmarks are from
cargo bench main
with 3.4 GHz i5-3570K (Ivy Bridge, 3rd gen.). - Shards are 1024 bytes.
- MiB/s is total amount of data,
i.e. original shards + recovery shards.
- For decoder this includes missing shards.
- Encode benchmark
- Includes
add_original_shard
andencode
ofReedSolomonEncoder
.
- Includes
- Decode benchmark
- Has two MiB/s values for 1% and 100% original shard loss, of maximum possible.
- Provides minimum required amount of shards to decoder.
- Includes
add_original_shard
,add_recovery_shard
anddecode
ofReedSolomonDecoder
.
original : recovery | MiB/s (encode) | MiB/s (decode) |
---|---|---|
100 : 100 | 229 | 73 ; 71 |
100 : 1 000 | 229 | 66 ; 66 |
1 000 : 100 | 222 | 65 ; 64 |
1 000 : 1 000 | 171 | 77 ; 74 |
1 000 : 10 000 | 149 | 53 ; 53 |
10 000 : 1 000 | 154 | 55 ; 55 |
10 000 : 10 000 | 103 | 39 ; 38 |
16 385 : 16 385 | 89 | 31 ; 31 |
32 768 : 32 768 | 107 | 50 ; 49 |
Benchmarks against other crates
Use cargo run --release --example quick-comparison
to run few simple benchmarks against reed-solomon-erasure
and reed-solomon-novelpoly
crates.
This crate is fastest when shard count exceeds 256 shards, except for one-time initialization (< 10 ms) which can dominate at really small data amounts.
Running tests
Some larger tests are marked #[ignore]
and are not run with cargo test
.
Use cargo test -- --ignored
to run those.
Safety
This crate doesn't currently use any unsafe
code.
However planned SIMD-optimized engines will need to use unsafe
,
but the intention is that nothing else will use unsafe
.
Credits
This crate is based on Leopard-RS by Christopher A. Taylor.