Beispiel #1
0
        public void Read(BinaryReader reader)
        {
            segmentPassCount = reader.ReadInt32();

            var passCountBuffer = GenericArrayPoolCacheHelper <long> .Caches().Rent(SubGridTreeConsts.CellsPerSubGrid);

            try
            {
                var fieldDescriptor = new EncodedBitFieldDescriptor();
                fieldDescriptor.Read(reader);

                using (var bfa = new BitFieldArray())
                {
                    bfa.Read(reader);
                    int bitLocation = 0;
                    bfa.ReadBitFieldVector(ref bitLocation, fieldDescriptor, SubGridTreeConsts.CellsPerSubGrid, passCountBuffer);
                }

                var counter = 0;

                for (var i = 0; i < SubGridTreeConsts.SubGridTreeDimension; i++)
                {
                    for (var j = 0; j < SubGridTreeConsts.SubGridTreeDimension; j++)
                    {
                        var passCount = (int)passCountBuffer[counter++];

                        if (passCount > 0)
                        {
                            AllocatePasses(i, j, passCount);

                            _passData[i, j].Passes.Count = passCount;
                            var passes = _passData[i, j].Passes;
                            for (int cpi = passes.Offset, limit = passes.OffsetPlusCount; cpi < limit; cpi++)
                            {
                                passes.Elements[cpi].Read(reader);
                            }
                        }
                    }
                }
            }
            finally
            {
                GenericArrayPoolCacheHelper <long> .Caches().Return(ref passCountBuffer);
            }
        }
Beispiel #2
0
        public void ReadBitFieldVector_FailWithStorageSize()
        {
            long[] values     = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var    descriptor = new EncodedBitFieldDescriptor();

            descriptor.RequiredBits = 4;

            using (var bfa = new BitFieldArray())
            {
                bfa.Initialise(descriptor.RequiredBits, values.Length - 1);

                int bitLocation = 0;
                bfa.WriteBitFieldVector(ref bitLocation, descriptor, values.Length - 1, values);

                Action act = () => bfa.ReadBitFieldVector(ref bitLocation, descriptor, values.Length, values);
                act.Should().Throw <ArgumentException>().WithMessage("Insufficient values present to satisfy a*");
            }
        }
Beispiel #3
0
        public void ReadBitFieldVector_FailWithValuesArraySize()
        {
            long[] values     = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var    descriptor = new EncodedBitFieldDescriptor();

            descriptor.RequiredBits = 4;

            using (var bfa = new BitFieldArray())
            {
                bfa.Initialise(descriptor.RequiredBits, values.Length);

                int bitLocation = 0;

                bfa.WriteBitFieldVector(ref bitLocation, descriptor, values.Length, values);

                Action act = () => bfa.ReadBitFieldVector(ref bitLocation, descriptor, values.Length + 1, values);
                act.Should().Throw <ArgumentException>().WithMessage("Supplied values array is null or not large enough*");
            }
        }
Beispiel #4
0
        public void ReadBitFieldVector_SuccessPartial()
        {
            long[] values     = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var    descriptor = new EncodedBitFieldDescriptor();

            descriptor.RequiredBits = 4;

            using (var bfa = new BitFieldArray())
            {
                bfa.Initialise(descriptor.RequiredBits, values.Length);

                int bitLocation = 0;
                bfa.WriteBitFieldVector(ref bitLocation, descriptor, values.Length, values);

                // Read the vector back
                bitLocation = 0;
                long[] outValues = new long[5];
                bfa.ReadBitFieldVector(ref bitLocation, descriptor, outValues.Length, outValues);
                bitLocation.Should().Be(outValues.Length * descriptor.RequiredBits);

                outValues.ForEach((l, i) => l.Should().Be(values[i]));
            }
        }
Beispiel #5
0
        public void ReadBitFieldVector_Success(byte valueBits)
        {
            long[] values = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var descriptor = new EncodedBitFieldDescriptor();

            descriptor.RequiredBits = valueBits;

            using (var bfa = new BitFieldArray())
            {
                bfa.Initialise(valueBits, values.Length);

                int bitLocation = 0;
                bfa.WriteBitFieldVector(ref bitLocation, descriptor, values.Length, values);

                // Read the vector back
                bitLocation = 0;
                long[] outValues = new long[values.Length];
                bfa.ReadBitFieldVector(ref bitLocation, descriptor, outValues.Length, outValues);
                bitLocation.Should().Be(outValues.Length * valueBits);

                outValues.Should().BeEquivalentTo(values);
            }
        }