// number of rows in the decoding matrix
int M = L + overhead;
// generate the original constraint matrix and allocate memory for overhead rows
ByteMatrix A = LinearSystem.generateConstraintMatrix(Kprime, overhead);
// initialize D
byte[][] D = new byte[M][T];
// populate D with the received source symbols
for (int esi : symbolsState.receivedSourceSymbols()) {
symbolsState.getSourceSymbol(esi).getCodeData(ByteBuffer.wrap(D[S + H + esi]));
}
/*
* for every repair symbol received
* - replace a missing source symbol's decoding matrix line for its corresponding line
* - populate D accordingly
*/
Iterator<Entry<Integer, RepairSymbol>> repairSymbolsIter = symbolsState.repairSymbols().iterator();
// identify missing source symbols and replace their lines with "repair lines"
for (Integer missingSrcESI : missingSourceSymbols()) {
Entry<Integer, RepairSymbol> next = repairSymbolsIter.next();
final int repairESI = next.getKey();
final int repairISI = SystematicIndices.getISI(repairESI, K(), Kprime);
final RepairSymbol repairSymbol = next.getValue();
final int row = S + H + missingSrcESI;
// replace line S + H + missingSrcESI with the line for encIndexes
Set<Integer> indexes = LinearSystem.encIndexes(Kprime, new Tuple(Kprime, repairISI));
A.clearRow(row); // must clear previous data first!
for (Integer col : indexes) {
A.set(row, col, (byte)1);
}
// fill in missing source symbols in D with the repair symbols
D[row] = repairSymbol.copyOfData(BufferType.ARRAY_BACKED).array();
}
// insert the values for overhead (repair) symbols
for (int row = L; row < M; row++) {
Entry<Integer, RepairSymbol> next = repairSymbolsIter.next();
final int repairESI = next.getKey();
final int repairISI = SystematicIndices.getISI(repairESI, K(), Kprime);
final RepairSymbol repairSymbol = next.getValue();
// generate the overhead lines
Set<Integer> indexes = LinearSystem.encIndexes(Kprime, new Tuple(Kprime, repairISI));
A.clearRow(row); // must clear previous data first!
for (Integer col : indexes) {
A.set(row, col, (byte)1);
}
// update D with the data for that symbol
D[row] = repairSymbol.copyOfData(BufferType.ARRAY_BACKED).array();
}