Overview
reed-solomon-erasure is an OCaml implementation of Reed-Solomon erasure coding.
It is a port of the Rust library reed-solomon-erasure, which is a port of several other libraries.
It provides functions for encoding, verifying, and reconstructing data and parity shards, and deals with string
, bytes
, and Core_kernel.Bigstring.t
You can install it via opam install reed-solomon-erasure
.
Example
open Reed_solomon_erasure
let () =
let r = ReedSolomon.make 3 2 in (* 3 data shards, 2 parity shards *)
let master_copy = [|"\000\001\002\003";
"\004\005\006\007";
"\008\009\010\011";
"\000\000\000\000"; (* last 2 rows are parity shards *)
"\000\000\000\000"|] in
(* Construct the parity shards *)
ReedSolomon.encode_str r master_copy;
(* Make a copy and transform it into option shards arrangement
for feeding into reconstruct_opt_str *)
let shards = RS_Shard_utils.shards_to_option_shards_str master_copy in
(* We can remove up to 2 shards, which may be data or parity shards *)
shards.(0) <- None;
shards.(4) <- None;
(* Try to reconstruct missing shards *)
ReedSolomon.reconstruct_opt_str r shards;
(* Convert back to normal shard arrangement *)
let result = RS_Shard_utils.option_shards_to_shards_str shards in
assert (ReedSolomon.verify_str r result);
assert (master_copy = result)
Performance
The encoding performance is shown below
Machine : laptop with Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz (max 2.70GHz) 2 Cores 4 Threads
Configuration | Klaus Post’s | reed-solomon-erasure (Rust) | ocaml-reed-solomon-erasure (bigstr) | … (bytes) | … (str) |
---|---|---|---|---|---|
10x2x1M | ~7800MB/s | ~4500MB/s | ~3000MB/s | ~1300MB/s | ~1300MB/s |
Links :
- Documentation
- OPAM
- Repo
- Archived GitHub repo (for those who keep track of things by stars)
EDIT: Fixed benchmark data