Package io.odilon.rs

Class ReedSolomon


  • public class ReedSolomon
    extends Object
    Reed-Solomon Coding over 8-bit values.
    • Constructor Detail

      • ReedSolomon

        public ReedSolomon​(int dataShardCount,
                           int parityShardCount)
        Initializes a new encoder/decoder.
    • Method Detail

      • getDataShardCount

        public int getDataShardCount()
        Returns the number of data shards.
      • getParityShardCount

        public int getParityShardCount()
        Returns the number of parity shards.
      • getTotalShardCount

        public int getTotalShardCount()
        Returns the total number of shards.
      • encodeParity

        public void encodeParity​(byte[][] shards,
                                 int offset,
                                 int byteCount)
        Encodes parity for a set of data shards.
        Parameters:
        shards - An array containing data shards followed by parity shards. Each shard is a byte array, and they must all be the same size.
        offset - The index of the first byte in each shard to encode.
        byteCount - The number of bytes to encode in each shard.
      • isParityCorrect

        public boolean isParityCorrect​(byte[][] shards,
                                       int firstByte,
                                       int byteCount)
        Returns true if the parity shards contain the right data.
        Parameters:
        shards - An array containing data shards followed by parity shards. Each shard is a byte array, and they must all be the same size.
        firstByte - The index of the first byte in each shard to check.
        byteCount - The number of bytes to check in each shard.
      • decodeMissing

        public void decodeMissing​(byte[][] shards,
                                  boolean[] shardPresent,
                                  int offset,
                                  int byteCount)
        Given a list of shards, some of which contain data, fills in the ones that don't have data. Quickly does nothing if all of the shards are present. If any shards are missing (based on the flags in shardsPresent), the data in those shards is recomputed and filled in.