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