Skip to content

Commit 352f79a

Browse files
committed
Just for comparison, add a log/exp version of the
shard/input/index coding loop.
1 parent 46ccc90 commit 352f79a

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

src/main/java/com/backblaze/erasure/CodingLoop.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface CodingLoop {
1212
new CodingLoop[] {
1313
new IndexShardInputExpCodingLoop(),
1414
new IndexShardInputTableCodingLoop(),
15+
new ShardInputIndexExpCodingLoop(),
1516
new ShardInputIndexTableCodingLoop()
1617
};
1718

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

src/main/java/com/backblaze/erasure/ShardInputIndexTableCodingLoop.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ public void codeSomeShards(
2020
byte[][] outputs, int outputCount,
2121
int offset, int byteCount) {
2222

23-
byte [] [] table = Galois.MULTIPLICATION_TABLE;
23+
final byte [] [] table = Galois.MULTIPLICATION_TABLE;
2424
for (int iShard = 0; iShard < outputCount; iShard++) {
25-
byte [] outputShard = outputs[iShard];
25+
final byte [] outputShard = outputs[iShard];
26+
final byte[] matrixRow = matrixRows[iShard];
2627
{
2728
final int iInput = 0;
2829
final byte [] inputShard = inputs[iInput];
29-
final byte [] multTableRow = table[matrixRows[iShard][iInput] & 0xFF];
30+
final byte [] multTableRow = table[matrixRow[iInput] & 0xFF];
3031
for (int iByte = offset; iByte < offset + byteCount; iByte++) {
3132
outputShard[iByte] = multTableRow[inputShard[iByte] & 0xFF];
3233
}
3334
}
3435
for (int iInput = 1; iInput < inputCount; iInput++) {
3536
final byte [] inputShard = inputs[iInput];
36-
final byte [] multTableRow = table[matrixRows[iShard][iInput] & 0xFF];
37+
final byte [] multTableRow = table[matrixRow[iInput] & 0xFF];
3738
for (int iByte = offset; iByte < offset + byteCount; iByte++) {
3839
outputShard[iByte] ^= multTableRow[inputShard[iByte] & 0xFF];
3940
}

0 commit comments

Comments
 (0)