int Rank1AccessBackend(int pos, out bool last_bit)
{
// in advance, we use pos as a simple counter of the remaining positions
int blockIndex = pos / 15 / this.BlockSize;
int classIndex = blockIndex * this.BlockSize;
int rank = this.AbsRank[blockIndex];
pos -= classIndex * 15;
int offset = this.AbsOffset[blockIndex];
int klass;
var ctx = new CtxCache (-1);
if (pos >= 15) {
for (; pos >= 15; pos -= 15) {
klass = this.DecodeClass (classIndex, ctx);
classIndex++;
rank += klass;
int numbits = NumBits[klass];
offset += numbits;
}
}
klass = this.DecodeClass (classIndex, ctx);
uint block = (uint)this.ReadBlock (klass, offset);
last_bit = BitAccess.GetBit ((int)block, pos);
rank += BitAccess.Rank1 (block, pos);
return rank;
}