Beispiel #1
0
        public void TestSpecificScenario3()
        {
            int dataBlockCount   = 5;
            int parityBlockCount = 3;
            int dataLength       = 1;


            var expectedData = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);

            var data         = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);
            var parityData   = ParityAlgorithm.GenerateParityData(data, parityBlockCount);
            var combinedData = data.Concat(parityData).ToList();

            combinedData[0].Data = null;
            combinedData[2].Data = null;
            combinedData[5].Data = null;


            var matrix = ParityAlgorithm.CreateParityMatrix(expectedData, parityBlockCount);

            Console.WriteLine($"Matrix: {matrix}");

            var repairedData = ParityAlgorithm.RecoverData(data, parityData, parityBlockCount);

            VerifyData(expectedData, repairedData);
        }
Beispiel #2
0
        private static void RunRepairTest(int dataBlockCount, int parityBlockCount, int dataLength)
        {
            var expectedData = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);



            for (int dataBlocksToDeleteCount = 1; dataBlocksToDeleteCount <= parityBlockCount; dataBlocksToDeleteCount++)
            {
                var rowsToDelete = DeleteDataHelper.DetermineAllPermutations(dataBlockCount + parityBlockCount, dataBlocksToDeleteCount);

                for (int zzz = 0; zzz < rowsToDelete.Count; zzz++)
                {
                    var toDelete = rowsToDelete[zzz];

                    var data         = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);
                    var parityData   = ParityAlgorithm.GenerateParityData(data, parityBlockCount);
                    var combinedData = data.Concat(parityData).ToList();

                    foreach (var rowToDelete in toDelete)
                    {
                        combinedData[rowToDelete].Data = null;
                    }

                    if (dataBlocksToDeleteCount == 2)
                    {
                    }

                    var repairedData = ParityAlgorithm.RecoverData(data, parityData, parityBlockCount);

                    VerifyData(expectedData, repairedData);
                }
            }
        }
Beispiel #3
0
        public void TestSpecificScenario2()
        {
            //This scenario works if using:
            //var val = Field.pow(baseList[column], row);

            int dataBlockCount   = 5;
            int parityBlockCount = 5;
            int dataLength       = 1;


            var expectedData = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);

            var data         = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);
            var parityData   = ParityAlgorithm.GenerateParityData(data, parityBlockCount);
            var combinedData = data.Concat(parityData).ToList();

            combinedData[1].Data = null;
            combinedData[2].Data = null;
            combinedData[3].Data = null;
            combinedData[6].Data = null;
            combinedData[7].Data = null;


            var matrix = ParityAlgorithm.CreateParityMatrix(expectedData, parityBlockCount);

            Console.WriteLine($"Matrix: {matrix}");

            //1 0 0 0 0
            //0 1 0 0 0
            //0 0 1 0 0
            //0 0 0 1 0
            //0 0 0 0 1
            //1 1 1 1 1
            //2 4 16 128 29
            //4 16 29 19 76
            //8 64 205 117 143
            //16 29 76 24 157

            var repairedData = ParityAlgorithm.RecoverData(data, parityData, parityBlockCount);

            //1 0 0 0 0
            //0 0 0 0 1
            //1 1 1 1 1
            //8 64 205 117 143
            //16 29 76 24 157

            VerifyData(expectedData, repairedData);
        }
Beispiel #4
0
        public void TestSpecificScenario()
        {
            //This scenario works if using:
            //var val = Field.pow(baseList[row], column);

            int dataBlockCount   = 5;
            int parityBlockCount = 5;
            int dataLength       = 1;


            var expectedData = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);

            var data         = GenerateTestDataHelper.GenerateTestData(dataBlockCount, dataLength);
            var parityData   = ParityAlgorithm.GenerateParityData(data, parityBlockCount);
            var combinedData = data.Concat(parityData).ToList();

            combinedData[0].Data = null;
            combinedData[3].Data = null;
            combinedData[4].Data = null;
            combinedData[5].Data = null;


            var matrix = ParityAlgorithm.CreateParityMatrix(expectedData, parityBlockCount);

            Console.WriteLine($"Matrix: {matrix}");
            //1 0 0 0 0
            //0 1 0 0 0
            //0 0 1 0 0
            //0 0 0 1 0
            //0 0 0 0 1
            //1 2 4 8 16
            //1 4 16 64 29
            //1 16 29 205 76
            //1 128 19 117 24
            //1 29 76 143 157

            var repairedData = ParityAlgorithm.RecoverData(data, parityData, parityBlockCount);

            //0 1 0 0 0
            //0 0 1 0 0
            //1 4 16 64 29
            //1 16 29 205 76
            //1 128 19 117 24

            VerifyData(expectedData, repairedData);
        }
Beispiel #5
0
        public static void GoParStuff()
        {
            //usage example
            Field f1 = new Field(15);
            Field f2 = new Field(8);
            Field f3 = f1 + f2;

            Console.WriteLine(f3);

            var f4 = f3 - f2;

            Console.WriteLine(f4);


            //var v1 = new CoolVector(1, 2, 3);
            //var v2 = new CoolVector(2, 1, 3);

            //var ar2 = new int[,] {
            //    { 1, 2, 3 },
            //    { 4, 5, 6 },
            //    { 7, 8, 9 }
            //};


            //var matrix = new Matrix(ar2);

            //var matrix2 = new Matrix(new int[,] {
            //    { 2 },
            //    { 1 },
            //    { 3 }
            //});



            //var result = matrix * v2;
            //Console.WriteLine(result);

            //var result2 = matrix * matrix2;
            //Console.WriteLine(result2);



            // 10
            // 3

            var ar1 = new int[, ] {
                { 1, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0 },
                { 0, 0, 1, 0, 0 },
                { 0, 0, 0, 1, 0 },
                { 0, 0, 0, 0, 1 },
                { 1, 1, 1, 1, 1 },
                { 1, 2, 3, 4, 5 }
            };


            var matrixField  = new MatrixField(ar1);
            var dataForField = new MatrixField(new int[, ] {
                { 10 },
                { 5 },
                { 8 },
                { 13 },
                { 2 }
            });
            var dataForField2 = new CoolVectorField(
                10,
                5,
                8,
                13,
                2
                );

            var result3 = matrixField * dataForField2;

            Console.WriteLine(result3);


            int parityBlocks = 2;

            var data = new List <Block <byte> >()
            {
                new Block <byte>()
                {
                    Data = new byte[] { 10 }
                },
                new Block <byte>()
                {
                    Data = new byte[] { 5 }
                },
                new Block <byte>()
                {
                    Data = new byte[] { 8 }
                },
                new Block <byte>()
                {
                    Data = new byte[] { 13 }
                },
                new Block <byte>()
                {
                    Data = new byte[] { 2 }
                },
            };


            var parMatrix     = ParityAlgorithm.CreateParityMatrix(data, parityBlocks);
            var parMatrixOnly = ParityAlgorithm.CreateParityOnlyMatrix(data, parityBlocks);

            Console.WriteLine();
            Console.Write(parMatrix);
            Console.WriteLine();
            Console.Write(parMatrixOnly);

            var recoveryData = ParityAlgorithm.GenerateParityData(data, parityBlocks);

            Console.WriteLine(string.Join(Environment.NewLine, recoveryData.Select(t => string.Join(",", t.Data))));



            //var totalData = data.Concat(recoveryData).ToList();
            //data[0].Data = null;
            data[1].Data = null;
            //data[2].Data = null;
            //data[3].Data = null;
            //data[4].Data = null;
            //recoveryData[0].Data = null;
            recoveryData[1].Data = null;
            ParityAlgorithm.RecoverData(data, recoveryData, parityBlocks);
            //ParityAlgorithm.RecoverDataV2(data, recoveryData, parityBlocks);



            var missing = new MatrixField(new int[, ]
            {
                { 1 },
                { 1 },
                { 1 },
                { 1 },
                { 1 },
                { 1 },
                { 1 }
            });
        }