public void Build(BitStream32 B, short blockSize)
{
this.N = (int)B.CountBits;
this.BlockSize = (short)blockSize;
this.InitClasses();
this.Offsets = new BitStream32 ();
IList<int> _L = new ListIFS (15, B);
IList<int> L;
if ((B.CountBits % 15) == 0) {
L = _L;
} else {
int D = _L.Count;
int C = 15 * D;
var ctx = new BitStreamCtx(0);
ctx.Seek(C);
int last_block = (int)B.Read(((int)B.CountBits) - C, ctx);
L = new ListGen<int>(delegate(int a) {
if (a == D) {
return last_block;
} else {
return _L[a];
}
}, D+1);
}
this.AbsRank = new int[(int)Math.Ceiling(((float)L.Count) / this.BlockSize)];
this.AbsOffset = new int[ this.AbsRank.Length ];
int I = 0;
int acc = 0;
for (int i = 0; i < L.Count; i++) {
var u = (short)L[i];
var klass = GetClass(u);
this.EncodeClass(klass);
if (i % this.BlockSize == 0) {
this.AbsRank[I] = acc;
this.AbsOffset[I] = (int)this.Offsets.CountBits;
I++;
}
var numbits = NumBits[klass];
if (numbits > 0) {
int offset = this.GetOffset (u, klass);
this.Offsets.Write (offset, numbits);
}
acc += klass;
}
}