Documentation ¶
Overview ¶
Erasure coding is similar to RAID based parity encoding, but is more generalized and powerful. When defining an erasure code, you specify a K and M variable. M is the number of shards you wish to encode and K is the number shards it takes to recreate your original data. Hence K must be less than M and usually not equal (as that would be a pointless encoding). The real magic with erasure coding is that fact that ANY K of the M shards can recreate the original data. For example, a erasure coding scheme of K=8 and M=12 means any four of the encoded shards can be lost while the original data can still be constructed from the valid remaining eight shards.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code struct { M int K int ShardLength int EncodeMatrix []byte // contains filtered or unexported fields }
Manages state of the erasure coding scheme and its values should be considered read-only.
func NewCode ¶
Constructor for creating a new erasure coding scheme. M is the total number of shards output by the encoding. K is the number of shards that can recreate any data that was encoded. Size is the size of the byte array to encode. It should be divisible by K as each shard will be Size / K in length. The maximum value for K and M is 127.
func (*Code) Decode ¶
Data buffer to decode must be of the (M/K)*Size given in the constructor. The error list must contain M-K values, corresponding to the shards with errors (eg. [0, 2, 4, 6]). Cache stores the decode matrices in a trie, enabling a faster decode with a memory tradeoff. The returned decoded data is the orignal data of length Size