From fb470cad7c539e5a2ef1bb3c8571a73e3ec709b5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 11 Feb 2019 01:39:58 +0000 Subject: [PATCH] Add ByteInputOutputTableCodingLoop class. --- .../ByteInputOutputTableCodingLoop.cs | 49 +++++++++++++++++++ .../Claunia.ReedSolomon.csproj | 1 + 2 files changed, 50 insertions(+) create mode 100644 Claunia.ReedSolomon/ByteInputOutputTableCodingLoop.cs diff --git a/Claunia.ReedSolomon/ByteInputOutputTableCodingLoop.cs b/Claunia.ReedSolomon/ByteInputOutputTableCodingLoop.cs new file mode 100644 index 0000000..e50c4a2 --- /dev/null +++ b/Claunia.ReedSolomon/ByteInputOutputTableCodingLoop.cs @@ -0,0 +1,49 @@ +/** + * One specific ordering/nesting of the coding loops. + * + * Copyright 2015, Backblaze, Inc. All rights reserved. + * Copyright © 2019 Natalia Portillo + */ + +namespace Claunia.ReedSolomon +{ + public class ByteInputOutputTableCodingLoop : CodingLoopBase + { + public override void CodeSomeShards(byte[][] matrixRows, byte[][] inputs, int inputCount, byte[][] outputs, + int outputCount, int offset, int byteCount) + { + byte[][] table = Galois.MULTIPLICATION_TABLE; + + for(int iByte = offset; iByte < offset + byteCount; iByte++) + { + { + int iInput = 0; + byte[] inputShard = inputs[iInput]; + byte inputByte = inputShard[iByte]; + + for(int iOutput = 0; iOutput < outputCount; iOutput++) + { + byte[] outputShard = outputs[iOutput]; + byte[] matrixRow = matrixRows[iOutput]; + byte[] multTableRow = table[matrixRow[iInput] & 0xFF]; + outputShard[iByte] = multTableRow[inputByte & 0xFF]; + } + } + + for(int iInput = 1; iInput < inputCount; iInput++) + { + byte[] inputShard = inputs[iInput]; + byte inputByte = inputShard[iByte]; + + for(int iOutput = 0; iOutput < outputCount; iOutput++) + { + byte[] outputShard = outputs[iOutput]; + byte[] matrixRow = matrixRows[iOutput]; + byte[] multTableRow = table[matrixRow[iInput] & 0xFF]; + outputShard[iByte] ^= multTableRow[inputByte & 0xFF]; + } + } + } + } + } +} \ No newline at end of file diff --git a/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj b/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj index 370a59c..921c6fc 100644 --- a/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj +++ b/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj @@ -39,6 +39,7 @@ +