From cff3ccd11d9ed09e01ce0b63455ed51e3147cecf Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 11 Feb 2019 01:42:50 +0000 Subject: [PATCH] Add OutputByteInputTableCodingLoop class. --- .../Claunia.ReedSolomon.csproj | 1 + .../OutputByteInputTableCodingLoop.cs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Claunia.ReedSolomon/OutputByteInputTableCodingLoop.cs diff --git a/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj b/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj index eddcc6b..ac934e8 100644 --- a/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj +++ b/Claunia.ReedSolomon/Claunia.ReedSolomon.csproj @@ -51,6 +51,7 @@ + diff --git a/Claunia.ReedSolomon/OutputByteInputTableCodingLoop.cs b/Claunia.ReedSolomon/OutputByteInputTableCodingLoop.cs new file mode 100644 index 0000000..7093500 --- /dev/null +++ b/Claunia.ReedSolomon/OutputByteInputTableCodingLoop.cs @@ -0,0 +1,38 @@ +/** + * One specific ordering/nesting of the coding loops. + * + * Copyright 2015, Backblaze, Inc. All rights reserved. + * Copyright © 2019 Natalia Portillo + */ + +namespace Claunia.ReedSolomon +{ + public class OutputByteInputTableCodingLoop : 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 iOutput = 0; iOutput < outputCount; iOutput++) + { + byte[] outputShard = outputs[iOutput]; + byte[] matrixRow = matrixRows[iOutput]; + + for(int iByte = offset; iByte < offset + byteCount; iByte++) + { + int value = 0; + + for(int iInput = 0; iInput < inputCount; iInput++) + { + byte[] inputShard = inputs[iInput]; + byte[] multTableRow = table[matrixRow[iInput] & 0xFF]; + value ^= multTableRow[inputShard[iByte] & 0xFF]; + } + + outputShard[iByte] = (byte)value; + } + } + } + } +} \ No newline at end of file