Class: Omnizip::Parity::ReedSolomonDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/parity/reed_solomon_decoder.rb

Overview

Pure Reed-Solomon decoder for recovering missing blocks This is algorithm-only code with no I/O dependencies

Recovers missing blocks by solving a system of linear equations using Gaussian elimination over GF(2^16)

Class Method Summary collapse

Class Method Details

.decode(present_blocks, recovery_blocks, missing_indices, block_size, total_inputs) ⇒ Hash<Integer, String>

Recover missing input blocks using available inputs and recovery blocks

Parameters:

  • present_blocks (Hash<Integer, String>)

    Map of index => block data for present inputs

  • recovery_blocks (Array<Hash>)

    Array of recovery block info: String, exponent: Integer

  • missing_indices (Array<Integer>)

    Indices of missing input blocks to recover

  • block_size (Integer)

    Size of each block in bytes

  • total_inputs (Integer)

    Total number of input blocks (present + missing)

Returns:

  • (Hash<Integer, String>)

    Map of recovered index => block data

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/omnizip/parity/reed_solomon_decoder.rb', line 19

def self.decode(present_blocks, recovery_blocks, missing_indices,
block_size, total_inputs)
  raise ArgumentError, "Block size must be even" if block_size.odd?

  if missing_indices.empty?
    raise ArgumentError,
          "No missing blocks to recover"
  end
  if recovery_blocks.size < missing_indices.size
    raise ArgumentError,
          "Not enough recovery blocks"
  end

  # Select base values using par2cmdline algorithm (same as encoder)
  bases = Par2cmdlineAlgorithm.compute_bases(total_inputs)

  # Build and solve the matrix system
  solved_matrix = build_and_solve_matrix(
    present_blocks.keys.sort,
    missing_indices.sort,
    recovery_blocks.map { |r| r[:exponent] },
    bases,
  )

  # Reconstruct missing blocks using solved matrix
  reconstruct_missing_blocks(
    present_blocks,
    recovery_blocks,
    missing_indices,
    solved_matrix,
    block_size,
  )
end