Copyright | (C) 2015 Nicolas Trangez 2015 Klaus Post 2015 Backblaze |
---|---|
License | MIT (see the file LICENSE) |
Maintainer | Nicolas Trangez <ikke@nicolast.be> |
Stability | provisional |
Safe Haskell | None |
Language | Haskell2010 |
Extensions |
|
This module implements the core Reed-Solomon data encoding and reconstruction routines.
- data Encoder
- new :: MonadThrow m => Int -> Int -> m Encoder
- type Matrix = Vector (Vector Word8)
- encode :: MonadThrow m => Encoder -> Matrix -> m Matrix
- verify :: MonadThrow m => Encoder -> Matrix -> m Bool
- reconstruct :: MonadThrow m => Encoder -> Vector (Maybe (Vector Word8)) -> m Matrix
- split :: MonadThrow m => Encoder -> Vector Word8 -> m Matrix
- join :: MonadThrow m => Encoder -> Matrix -> Int -> m (Vector Word8)
- data ShardType
- data ValueError
- data SIMDInstructions
- simdInstructions :: IO (Maybe SIMDInstructions)
Core API
:: 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.
:: 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.
:: 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
Enumeration of kinds of shards.
data ValueError Source
Exception type used to denote invalid input.
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.
Bounded SIMDInstructions Source | |
Enum SIMDInstructions Source | |
Eq SIMDInstructions Source | |
Ord SIMDInstructions Source | |
Show SIMDInstructions Source |
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.