예제 #1
0
파일: RRRv2.cs 프로젝트: Pako125/natix
 protected override int DecodeClass(int i, CtxCache ctx)
 {
     int klass;
     // Console.WriteLine("XXXXX i: {0}, offset: {1}", i, ctx.Offset);
     if (ctx.Offset == -1 || ctx.prev_item + 1 != i) {
         klass = this.LI.GetItem(i, ctx);
     } else {
         klass = this.LI.GetNext(ctx);
     }
     ctx.prev_item = i;
     // var klass = this.Klasses[i];
     // var klass = this.LI[i];
     if ((0x1 & klass) == 0x1) { // check for odd
         klass >>= 1; // removing encding as odd
         klass = 15 - klass; // going right to left
     }
     else {
         klass >>= 1; // removing
     }
     return klass;
 }
예제 #2
0
파일: RRR.cs 프로젝트: Pako125/natix
 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;
 }
예제 #3
0
파일: RRR.cs 프로젝트: Pako125/natix
 protected virtual int DecodeClass(int i, CtxCache ctx)
 {
     var klass = this.Klasses[i];
     return klass;
 }
예제 #4
0
파일: RRR.cs 프로젝트: Pako125/natix
 public override int Select1(int rank)
 {
     if (rank < 1) {
         return -1;
     }
     int blockIndex = GenericSearch.FindFirst<int> (rank, this.AbsRank);
     if (this.AbsRank[blockIndex] == rank) {
         blockIndex--;
     }
     int classIndex = blockIndex * this.BlockSize;
     rank -= this.AbsRank[blockIndex];
     int pos = classIndex * 15;
     int offset = this.AbsOffset[blockIndex];
     int klass;
     var ctx = new CtxCache (-1);
     while (rank > 0) {
         klass = this.DecodeClass (classIndex, ctx);
         if (rank - klass <= 0) {
             break;
         }
         classIndex++;
         pos += 15;
         rank -= klass;
         int numbits = NumBits[klass];
         offset += numbits;
     }
     if (rank > 0) {
         klass = this.DecodeClass (classIndex, ctx);
         uint block = (uint)this.ReadBlock (klass, offset);
         // Console.WriteLine ("rank: {0}, pos: {1}, block: {2}, klass: {3}, offset: {4}",
         //	rank, pos, block, klass, offset);
         pos += BitAccess.Select1 (block, rank);
     }
     return pos;
 }