|
| 1 | +/** |
| 2 | + * One specific ordering/nesting of the coding loops. |
| 3 | + * |
| 4 | + * Copyright 2015, Backblaze, Inc. All rights reserved. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.backblaze.erasure; |
| 8 | + |
| 9 | +public class ShardInputIndexExpCodingLoop implements CodingLoop { |
| 10 | + |
| 11 | + @Override |
| 12 | + public String getName() { |
| 13 | + return "shard/input/index (exp table)"; |
| 14 | + } |
| 15 | + |
| 16 | + @Override |
| 17 | + public void codeSomeShards( |
| 18 | + byte[][] matrixRows, |
| 19 | + byte[][] inputs, int inputCount, |
| 20 | + byte[][] outputs, int outputCount, |
| 21 | + int offset, int byteCount) { |
| 22 | + |
| 23 | + for (int iShard = 0; iShard < outputCount; iShard++) { |
| 24 | + final byte [] outputShard = outputs[iShard]; |
| 25 | + final byte [] matrixRow = matrixRows[iShard]; |
| 26 | + { |
| 27 | + final int iInput = 0; |
| 28 | + final byte [] inputShard = inputs[iInput]; |
| 29 | + for (int iByte = offset; iByte < offset + byteCount; iByte++) { |
| 30 | + outputShard[iByte] = Galois.multiply(matrixRow[iInput], inputShard[iByte]); |
| 31 | + } |
| 32 | + } |
| 33 | + for (int iInput = 1; iInput < inputCount; iInput++) { |
| 34 | + final byte [] inputShard = inputs[iInput]; |
| 35 | + for (int iByte = offset; iByte < offset + byteCount; iByte++) { |
| 36 | + outputShard[iByte] ^= Galois.multiply(matrixRow[iInput], inputShard[iByte]); |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean checkSomeShards( |
| 44 | + byte[][] matrixRows, |
| 45 | + byte[][] inputs, int inputCount, |
| 46 | + byte[][] toCheck, int checkCount, |
| 47 | + int offset, int byteCount) { |
| 48 | + |
| 49 | + // TODO: structure like the coding loop (use a temporary buffer?) |
| 50 | + // |
| 51 | + // Checking loop doesn't match the coding loop. Need to figure |
| 52 | + // out how to do it. The problem is that the coding loop uses |
| 53 | + // the output shards as temporary working space, so the original |
| 54 | + // value isn't there to check after computing the new value. |
| 55 | + |
| 56 | + byte [] [] table = Galois.MULTIPLICATION_TABLE; |
| 57 | + for (int iByte = offset; iByte < offset + byteCount; iByte++) { |
| 58 | + for (int iRow = 0; iRow < checkCount; iRow++) { |
| 59 | + byte [] matrixRow = matrixRows[iRow]; |
| 60 | + int value = 0; |
| 61 | + for (int c = 0; c < inputCount; c++) { |
| 62 | + value ^= table[matrixRow[c] & 0xFF][inputs[c][iByte] & 0xFF]; |
| 63 | + } |
| 64 | + if (toCheck[iRow][iByte] != (byte) value) { |
| 65 | + return false; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + return true; |
| 70 | + } |
| 71 | +} |
0 commit comments