public void Build(IEnumerable<int> orderedList, int n, short b, IIEncoder32 coder = null)
{
this.N = n;
this.B = b;
this.M = 0;
if (coder == null) {
coder = new EliasDelta ();
}
this.Coder = coder;
int prev = -1;
var ctx = new BitStreamCtxRL ();
foreach (var current in orderedList) {
if (current == 0) {
prev = AccStart;
}
this.M++;
int diff = current - prev;
//Console.WriteLine ("DIFF {0}, num: {1}", diff, num++);
if (diff == 1) {
++ctx.run_len;
} else {
this.Commit (ctx);
// Console.WriteLine ("%%%%%% diff: {0}, prev: {1}, curr: {2}", diff, prev, current);
Coder.Encode (this.Stream, diff);
}
if (this.M % this.B == 0) {
this.Commit (ctx);
this.Samples.Add (current);
this.Offsets.Add (this.Stream.CountBits);
}
if (current >= this.N) {
this.N = current + 1;
}
prev = current;
}
this.Commit (ctx);
/*for (int i = 0; i < this.Samples.Count; i++) {
Console.WriteLine ("-- i: {0}, samples: {1}, offset: {2}", i, Samples[i], Offsets[i]);
}*/
}