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)); } } }
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); }