Class: Omnizip::Parity::ChunkedBlockProcessor
- Inherits:
-
Object
- Object
- Omnizip::Parity::ChunkedBlockProcessor
- Defined in:
- lib/omnizip/parity/chunked_block_processor.rb
Overview
Constant Summary collapse
- DEFAULT_CHUNK_SIZE =
Default chunk size (1MB)
1024 * 1024
Instance Attribute Summary collapse
-
#block_size ⇒ Integer
readonly
Block size in bytes.
-
#chunk_size ⇒ Integer
readonly
Chunk size for processing.
-
#matrix ⇒ ReedSolomonMatrix
readonly
RS matrix with precomputed coefficients.
-
#missing_indices ⇒ Array<Integer>
readonly
Missing block indices to recover.
-
#present_blocks ⇒ Hash<Integer, String>
readonly
Present input blocks (index => data).
-
#recovery_blocks ⇒ Hash<Integer, String>
readonly
Recovery blocks (exponent => data).
Instance Method Summary collapse
-
#initialize(matrix, present_blocks, recovery_blocks, missing_indices, block_size, chunk_size: DEFAULT_CHUNK_SIZE) ⇒ ChunkedBlockProcessor
constructor
Initialize processor.
-
#process_all ⇒ Hash<Integer, String>
Process all blocks incrementally.
Constructor Details
#initialize(matrix, present_blocks, recovery_blocks, missing_indices, block_size, chunk_size: DEFAULT_CHUNK_SIZE) ⇒ ChunkedBlockProcessor
Initialize processor
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 41 def initialize(matrix, present_blocks, recovery_blocks, missing_indices, block_size, chunk_size: DEFAULT_CHUNK_SIZE) @matrix = matrix @present_blocks = present_blocks @recovery_blocks = recovery_blocks @missing_indices = missing_indices.sort @block_size = block_size # Ensure chunk_size is even (we process 16-bit words) requested_chunk = [chunk_size, block_size].min @chunk_size = requested_chunk - (requested_chunk % 2) end |
Instance Attribute Details
#block_size ⇒ Integer (readonly)
Returns Block size in bytes.
28 29 30 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 28 def block_size @block_size end |
#chunk_size ⇒ Integer (readonly)
Returns Chunk size for processing.
31 32 33 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 31 def chunk_size @chunk_size end |
#matrix ⇒ ReedSolomonMatrix (readonly)
Returns RS matrix with precomputed coefficients.
16 17 18 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 16 def matrix @matrix end |
#missing_indices ⇒ Array<Integer> (readonly)
Returns Missing block indices to recover.
25 26 27 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 25 def missing_indices @missing_indices end |
#present_blocks ⇒ Hash<Integer, String> (readonly)
Returns Present input blocks (index => data).
19 20 21 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 19 def present_blocks @present_blocks end |
#recovery_blocks ⇒ Hash<Integer, String> (readonly)
Returns Recovery blocks (exponent => data).
22 23 24 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 22 def recovery_blocks @recovery_blocks end |
Instance Method Details
#process_all ⇒ Hash<Integer, String>
Process all blocks incrementally
Implements: x = A^-1 * b where b = recovery - present_contributions
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 59 def process_all # Initialize output blocks (all zeros) recovered = {} missing_indices.each do |idx| recovered[idx] = "\x00".b * block_size end # Process block chunk by chunk block_offset = 0 while block_offset < block_size current_chunk_size = [chunk_size, block_size - block_offset].min process_chunk_at_offset(recovered, block_offset, current_chunk_size) block_offset += current_chunk_size end recovered end |