public void Store(BinaryWriter writer, Func <int, decimal> values, int count)
        {
            writer.Write(VERSION);

            DeltaCompression.Helper helper = null;
            long[] array = null;
            int    digits;

            try
            {
                digits = GetMaxDigits(values, count);
                if (digits <= 15)
                {
                    helper = new DeltaCompression.Helper();
                    array  = new long[count];

                    decimal koef = (decimal)Math.Pow(10, digits);
                    for (int i = 0; i < count; i++)
                    {
                        decimal value = values(i);
                        long    v     = checked ((long)Math.Round(value * koef));

                        array[i] = v;
                        helper.Add(v);
                    }
                }
                else
                {
                    digits = -1;
                }
            }
            catch (OverflowException)
            {
                digits = -1;
            }

            writer.Write((sbyte)digits);
            if (digits >= 0)
            {
                DeltaCompression.Compress(writer, array, 0, count, helper);
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    writer.Write(values(i));
                }
            }
        }
Beispiel #2
0
        public void Store(BinaryWriter writer, Func <int, decimal> values, int count)
        {
            DeltaCompression.Helper helper    = null;
            List <long>             rawValues = null;
            int maxDigits;

            try
            {
                maxDigits = GetMaxDigits(values, count);
                if (maxDigits <= 15)
                {
                    helper    = new DeltaCompression.Helper();
                    rawValues = new List <long>(count);

                    decimal koef = (decimal)Math.Pow(10, maxDigits);
                    for (int i = 0; i < count; i++)
                    {
                        decimal value = values(i);
                        long    v     = checked ((long)Math.Round(value * koef));
                        helper.AddValue(v);
                        rawValues.Add(v);
                    }
                }
                else
                {
                    maxDigits = -1;
                }
            }
            catch (OverflowException)
            {
                maxDigits = -1;
            }

            writer.Write((sbyte)maxDigits);
            if (maxDigits >= 0)
            {
                DeltaCompression.CoreCompress(writer, rawValues, helper);
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    writer.Write(values(i));
                }
            }
        }
Beispiel #3
0
        public void Store(BinaryWriter writer, Func <int, long> values, int count)
        {
            writer.Write(VERSION);

            long[] array = new long[count];

            int index = factors.Length - 1;

            for (int i = 0; i < count; i++)
            {
                long value = values(i);
                array[i] = value;

                while (index >= 0)
                {
                    if (value % factors[index] == 0)
                    {
                        break;
                    }
                    else
                    {
                        index--;
                    }
                }
            }

            long factor = index >= 0 ? factors[index] : 1;

            DeltaCompression.Helper helper = new DeltaCompression.Helper();
            for (int i = 0; i < count; i++)
            {
                array[i] /= factor;
                helper.Add(array[i]);
            }

            CountCompression.Serialize(writer, checked ((ulong)factor));
            DeltaCompression.Compress(writer, array, 0, count, helper);
        }
        public void Store(BinaryWriter writer, Func <int, long> values, int count)
        {
            List <long> list = new List <long>(count);

            int index = factors.Length - 1;

            for (int i = 0; i < count; i++)
            {
                long value = values(i);
                list.Add(value);

                while (index >= 0)
                {
                    if (value % factors[index] == 0)
                    {
                        break;
                    }
                    else
                    {
                        index--;
                    }
                }
            }

            long factor = index >= 0 ? factors[index] : 1;

            DeltaCompression.Helper helper = new DeltaCompression.Helper();
            for (int i = 0; i < count; i++)
            {
                list[i] = list[i] / factor;
                helper.AddValue(list[i]);
            }

            CountCompression.Serialize(writer, checked ((ulong)factor));
            DeltaCompression.CoreCompress(writer, list, helper);
        }