reedsolomon-0.0.4.2: Reed-Solomon Erasure Coding in Haskell

Copyright(C) 2015 Nicolas Trangez 2015 Klaus Post 2015 Backblaze
LicenseMIT (see the file LICENSE)
MaintainerNicolas Trangez <ikke@nicolast.be>
Stabilityprovisional
Safe HaskellNone
LanguageHaskell2010
Extensions
  • Cpp
  • ScopedTypeVariables
  • DeriveDataTypeable
  • ExplicitForAll

Data.ReedSolomon

Contents

Description

This module implements the core Reed-Solomon data encoding and reconstruction routines.

Synopsis

Core API

data Encoder Source

A Reed-Solomon encoder.

Instances

new Source

Arguments

:: MonadThrow m 
=> Int

Number of data shards ([0, 255])

-> Int

Number of parity shards ([0, ])

-> m Encoder 

Construct a new Encoder.

Throws InvalidNumberOfShards when dataShards or parityShards is out of range.

An Encoder can safely be reused between encoding and reconstruction rounds, as well as shared between threads.

type Matrix = Vector (Vector Word8) Source

A row-major Matrix of bytes.

encode Source

Arguments

:: MonadThrow m 
=> Encoder

Encoder to use

-> Matrix

Data shards

-> m Matrix 

Encode some data shards into parity shards.

The number of rows in the given matrix must match the number of data shards the Encoder requires, otherwise InvalidNumberOfShards is thrown. If all shards are empty, EmptyShards is thrown. Similarly, when shards are of inconsistent length, InvalidShardSize is thrown.

verify :: MonadThrow m => Encoder -> Matrix -> m Bool Source

Verify the code chunks against the data.

This function will re-encode the data chunks, and validate the code chunks in the given Matrix are equal.

reconstruct Source

Arguments

:: MonadThrow m 
=> Encoder

Encoder to use

-> Vector (Maybe (Vector Word8))

Partial data and parity shards

-> m Matrix

Reconstructed data and parity shards

Reconstruct partial data.

Data conversion utilities

split :: MonadThrow m => Encoder -> Vector Word8 -> m Matrix Source

Split data into shards that can be encoded by the given Encoder.

If required, the last shard is padded with zeros to match size.

join :: MonadThrow m => Encoder -> Matrix -> Int -> m (Vector Word8) Source

Join shards into a single Vector of given size.

Note: This function concatenates all data through copies, which is inefficient. When writing the data to a file or socket, consider doing so without joining in-memory.

Exceptions

data ShardType Source

Enumeration of kinds of shards.

Instances

data ValueError Source

Exception type used to denote invalid input.

Constructors

InvalidNumberOfShards ShardType Int

Invalid number of shards

EmptyShards

All shards are empty

InvalidShardSize

A shard of invalid size was passed

InvalidDataSize

The length of the passed data is invalid

Determining runtime SIMD instruction support

data SIMDInstructions Source

Enumeration of SIMD instruction sets.

Constructors

Generic 
SSE2 
SSSE3 
AVX 
AVX2 
NEON 
AltiVec 

simdInstructions :: IO (Maybe SIMDInstructions) Source

Retrieve the SIMD instruction set used by native Galois field operations.

Returns Nothing when the library is compiled without SIMD support, otherwise Just the runtime-determined SIMD instruction set used for optimized Galois field calculations.