public RankSelectBlocks(BitStream32 bitmap, short superBlockSize, short blockSize) { this.SetState (bitmap.GetIList32(), (int)bitmap.CountBits, superBlockSize, blockSize, null, null); // Checking ranges of our data types int bs = this.BitBlocks.Count; this.SuperBlocks = new int[bs / (this.SuperBlockSize * this.BlockSize)]; this.Blocks = new short[bs / this.BlockSize - this.SuperBlocks.Length]; int abs = 0; short rel = 0; //Console.WriteLine ("rel-rank: {0}, abs-rank: {1}, bitmap-ints: {2}", this.Blocks.Length, this.SuperBlocks.Length, this.Bitmap.CountUInt32); var Lbuffer = bitmap.GetIList32 (); for (int relindex = 0, absindex = 0, index = 0, relcounter = this.SuperBlockSize - 1; relindex <= this.Blocks.Length; index += this.BlockSize,relcounter--) { int count = Math.Min (this.BlockSize, bitmap.Count32 - index); // Console.WriteLine ("index: {0}, count: {1}, block-size: {2}, super-block-size: {3}, bitmap-uintsize: {4}", // index, count, this.BlockSize, this.SuperBlockSize, bitmap.CountUInt32); rel += (short)this.SeqRank1 (Lbuffer, index, count, -1); // Console.WriteLine ("absindex: {0}, abs: {1}, relcounter", absindex, abs, relcounter); if (relcounter == 0) { abs += rel; if (absindex < this.SuperBlocks.Length) { // Console.WriteLine ("========> absindex: {0}, abs: {1}, rel: {2}", absindex, abs, rel); this.SuperBlocks[absindex] = abs; } relcounter = this.SuperBlockSize; absindex++; rel = 0; } else { if (relindex < this.Blocks.Length) { this.Blocks[relindex] = rel; } relindex++; } } /*Console.WriteLine ("---- Precomputed tables"); Console.WriteLine ("rel-rank: {0}, abs-rank: {1}, bitmap-ints: {2}", this.Blocks.Length, this.SuperBlocks.Length, this.Bitmap.CountUInt32); Console.WriteLine ("---- Absolute values"); for (int i = 0; i < this.SuperBlocks.Length; i++) { Console.WriteLine ("TABLE ABS i: {0}, abs_rank: {1}, bit-position: {2}", i, this.SuperBlocks[i], 32 * (i + 1) * this.BlockSize * this.SuperBlockSize); } Console.WriteLine ("---- Relative values"); for (int i = 0; i < this.Blocks.Length; i++) { Console.WriteLine ("TABLE REL i: {0}, rel_rank: {1}, bit-position: {2}", i, this.Blocks[i], (i + 1) * 32 * this.BlockSize); }*/ }