Read() public method

public Read ( int numbits, BitStreamCtx ctx ) : System.UInt64
numbits int
ctx BitStreamCtx
return System.UInt64
コード例 #1
0
ファイル: UltimateSearchCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 stream, BitStreamCtx ctx)
 {
     int min = 0;
     int galloping = 1;
     int check;
     int u = 0;
     while (true) {
         check = (1 << galloping) - 1;
         if (stream.Read (ctx)) {
             min = check + 1;
             ++galloping;
         } else {
             if (galloping == 1) {
                 if (stream.Read(ctx)) {
                     u++;
                 }
                 return u;
             } else {
                 u += min;
                 min = 0;
                 galloping = 1;
             }
         }
     }
 }
コード例 #2
0
ファイル: UltimateSearchCoding64.cs プロジェクト: sadit/natix
 public long Decode(BitStream32 stream, BitStreamCtx ctx)
 {
     long min = 0;
     long check;
     long u = 0;
     int galloping = 1;
     while (true) {
         check = (1L << galloping) - 1L;
         if (stream.Read (ctx)) {
             min = check + 1L;
             ++galloping;
         } else {
             if (galloping == 1) {
                 if (stream.Read (ctx)) {
                     u++;
                 }
                 return u;
             } else {
                 u += min;
                 min = 0L;
                 galloping = 1;
             }
         }
     }
 }
コード例 #3
0
ファイル: UnaryCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     int u = Buffer.ReadZeros (ctx);
     //int u = Buffer.ReadOnes ();
     Buffer.Read (ctx);
     return u;
 }
コード例 #4
0
ファイル: EliasGamma64.cs プロジェクト: sadit/natix
 public long Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     int numbits = unary.Decode (Buffer, ctx);
     if (numbits == 0) {
         return 1L;
     } else {
         ulong number;
         if (numbits <= 32) {
             number = Buffer.Read (numbits, ctx);
         } else {
             number = Buffer.Read (32, ctx);
             number |= Buffer.Read (numbits - 32, ctx) << 32;
         }
         number = (1UL << numbits) | number;
         return (long)number;
     }
 }
コード例 #5
0
ファイル: BinaryCoding.cs プロジェクト: sadit/natix
 public int ArrayGet(BitStream32 Buffer, int pos)
 {
     long p = pos;
     p *= this.NumBits;
     var ctx = new BitStreamCtx (p);
     int number = (int)Buffer.Read (this.NumBits, ctx);
     return number;
 }
コード例 #6
0
ファイル: EliasGamma.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     int numbits = unary.Decode (Buffer, ctx);
     if (numbits == 0) {
         return 1;
     } else {
         int number = (int) Buffer.Read (numbits, ctx);
         return (1 << numbits) | number;
     }
 }
コード例 #7
0
ファイル: EliasDelta64.cs プロジェクト: sadit/natix
        public long Decode(BitStream32 Buffer, BitStreamCtx ctx)
        {
            int len_code = gammacoder.Decode (Buffer, ctx);
            --len_code;
            if (len_code == 0) {
                return 1L;
            } else {
                ulong number;
                if (len_code <= 32) {
                    number = Buffer.Read (len_code, ctx);
                } else {
                    number = Buffer.Read (32, ctx);
                    number |= Buffer.Read (len_code - 32, ctx) << 32;
                }
                number = (1UL << len_code) | number;
                return (long)number;

            }
        }
コード例 #8
0
ファイル: EliasDelta.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     int len_code = gammacoder.Decode (Buffer, ctx);
     len_code--;
     if (len_code == 0) {
         return 1;
     } else {
         int output = (int)Buffer.Read (len_code, ctx);
         // Console.WriteLine ("Decode> count: {0}, output: {1}", count, output);
         return (1 << len_code) + output;
     }
 }
コード例 #9
0
ファイル: EqualSizeCoder.cs プロジェクト: sadit/natix
 public List<WTM_Symbol> Encode(int symbol, List<WTM_Symbol> output = null)
 {
     var coderstream = new BitStream32 ();
     this.Coder.Encode (coderstream, symbol);
     int numbits = (int)coderstream.CountBits;
     var ctx = new BitStreamCtx (0);
     if (output == null) {
         output = new List<WTM_Symbol> ();
     }
     for (int i = 0; i < numbits; i+= this.bits_per_code) {
         int code = (int)coderstream.Read (this.bits_per_code, ctx);
         output.Add(new WTM_Symbol(code, (byte) Math.Min (this.bits_per_code, numbits - i)));
         // Console.WriteLine("get-mini symbol: {0}, numbits: {1}, i: {2}, code: {3}", symbol, numbits, i, code);
     }
     return output;
 }
コード例 #10
0
ファイル: BinarySearchCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 stream, int N, BitStreamCtx ctx)
 {
     int min = 0;
     int max = N - 1;
     int mid;
     do {
         mid = (min >> 1) + (max >> 1);
         if (1 == (min & 1 & max)) {
             mid++;
         }
         if (!stream.Read (ctx)) {
             max = mid;
         } else {
             min = mid + 1;
         }
     } while (min < max);
     return min;
 }
コード例 #11
0
ファイル: HuffmanCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 stream, BitStreamCtx ctx)
 {
     HuffmanInner node = this.Huffman.Root;
     while (true) {
         bool b = stream.Read (ctx);
         HuffmanNode next;
         if (b) {
             next = node.Right;
         } else {
             next = node.Left;
         }
         var leaf = next as HuffmanLeaf;
         if (leaf != null) {
             return leaf.Symbol;
         }
         node = next as HuffmanInner;
     }
 }
コード例 #12
0
ファイル: BinarySearchCoding64.cs プロジェクト: sadit/natix
 public long Decode(BitStream32 stream, long N, BitStreamCtx ctx)
 {
     long min = 0;
     long max = N - 1;
     long mid;
     do {
         mid = (min >> 1) + (max >> 1);
         if (1L == (min & 1L & max)) {
             mid++;
         }
         if (!stream.Read (ctx)) {
             max = mid;
         } else {
             min = mid + 1L;
         }
     } while (min < max);
     return min;
 }
コード例 #13
0
ファイル: DoublingSearchCoding64.cs プロジェクト: sadit/natix
 public long Decode(BitStream32 stream, BitStreamCtx ctx)
 {
     long min = 0;
     long check;
     int galloping = 1;
     while (true) {
         check = (1L << galloping) - 1L;
         if (stream.Read (ctx)) {
             min = check + 1L;
             ++galloping;
         } else {
             if (min == 0L) {
                 return this.SecondCoding.Decode (stream, 2, ctx);
             } else {
                 return min + this.SecondCoding.Decode (stream, min, ctx);
             }
         }
     }
 }
コード例 #14
0
ファイル: DoublingSearchCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 stream, BitStreamCtx ctx)
 {
     int min = 0;
     int galloping = 1;
     int check;
     while (true) {
         check = (1 << galloping) - 1;
         if (stream.Read (ctx)) {
             min = check + 1;
             ++galloping;
         } else {
             if (min == 0) {
                 return this.SecondCoding.Decode(stream, 2, ctx);
             } else {
                 return min + this.SecondCoding.Decode(stream, min, ctx);
             }
         }
     }
 }
コード例 #15
0
ファイル: EliasGamma32.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     // int numbits = unary.Decode (Buffer, ctx);
     // the idea is to replace unary coder by explicit inline code such that (hopefully)
     // both "code" and "numbits" are stored into registers
     var M = (int)Math.Min (32, Buffer.CountBits - ctx.Offset);
     var code = (uint)Buffer.Read (M, ctx);
     if ((code & 0x1) == 1) {
         ctx.Offset -= M - 1;
         return 1;
     }
     if (code == 0) {
         throw new ArgumentException ("Integers larger than 31 bits are not supported by EliasGamma32");
     }
     int numbits = 0;
     // Console.WriteLine ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx ");
     // Console.WriteLine ("xxxxx start-read> offset: {0},\t numbits: {1},\t code: {2}", ctx.Offset, numbits, BitAccess.ToAsciiString (code));
     while ((code & 0xFF) == 0) {
         numbits += 8;
         code >>= 8;
     }
     if ((code & 0xF) == 0) {
         numbits += 4;
         code >>= 4;
     }
     while ((code & 0x1) == 0) {
         numbits += 1;
         code >>= 1;
     }
     code >>= 1;
     // Console.WriteLine ("xxxxx unary-read> offset: {0},\t numbits: {1},\t code: {2}", ctx.Offset, numbits, BitAccess.ToAsciiString (code));
     if (numbits >= 16) {
         int in_cache = M - 1 - numbits;
         code |= ((uint)Buffer.Read (numbits - in_cache, ctx)) << in_cache;
     } else {
         ctx.Offset -= M - ((numbits << 1) + 1);
         code &= (1u << numbits) - 1;
     }
     // Console.WriteLine ("xxxxx final-read0> offset: {0},\t numbits: {1},\t code: {3},\t number: {2}", ctx.Offset, numbits, code, BitAccess.ToAsciiString (code));
     code |= (1u << numbits);
     // Console.WriteLine ("xxxxx final-read1> offset: {0},\t numbits: {1},\t code: {3},\t number: {2}", ctx.Offset, numbits, code, BitAccess.ToAsciiString (code));
     return (int)code;
 }
コード例 #16
0
ファイル: WaveletTree.cs プロジェクト: Pako125/natix
 public int Rank(int symbol, int position)
 {
     var coderstream = new BitStream32 ();
     this.Coder.Encode (coderstream, symbol);
     //this.CoderStream.Seek (0);
     var ctx = new BitStreamCtx (0);
     int numbits = (int)coderstream.CountBits;
     var node = this.Root;
     for (int i = 0; i < numbits; i++) {
         bool b = coderstream.Read (ctx);
         if (b) {
             position = node.B.Rank1 (position) - 1;
             if (i + 1 < numbits) {
                 node = node.Right as WaveletInner;
             }
         } else {
             position = node.B.Rank0 (position) - 1;
             if (i + 1 < numbits) {
                 node = node.Left as WaveletInner;
             }
         }
         if (node == null) {
             return 0;
         }
     }
     return position + 1;
 }
コード例 #17
0
ファイル: BinaryCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     int number = (int)Buffer.Read (this.NumBits, ctx);
     return number;
 }
コード例 #18
0
ファイル: RRR.cs プロジェクト: sadit/natix
 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;
     }
 }
コード例 #19
0
ファイル: BlockCoding.cs プロジェクト: sadit/natix
 public int Decode(BitStream32 Buffer, BitStreamCtx ctx)
 {
     int skip = this.SkipCoder.Decode (Buffer, ctx);
     int output = (int)Buffer.Read (this.Power, ctx);
     return (skip << this.Power) | output;
 }
コード例 #20
0
ファイル: WaveletTree.cs プロジェクト: Pako125/natix
 protected void Add(int symbol)
 {
     var coderstream = new BitStream32 ();
     coderstream.Clear ();
     this.Coder.Encode(coderstream, symbol);
     var ctx = new BitStreamCtx (0);
     // this.CoderStream.Seek (0);
     int numbits = (int)coderstream.CountBits;
     var node = this.Root;
     for (int b = 0; b < numbits; b++) {
         var bitcode = coderstream.Read (ctx);
         (node.B as FakeBitmap).Write (bitcode);
         if (bitcode) {
             if (numbits == b + 1) {
                 if (node.Right == null) {
                     var leaf = new WaveletLeaf (node, symbol);
                     // this.Alphabet.Add (leaf);
                     this.Alphabet [symbol] = leaf;
                     node.Right = leaf;
                 } else {
                     (node.Right as WaveletLeaf).Increment ();
                 }
             } else {
                 if (node.Right == null) {
                     node.Right = new WaveletInner (node, true);
                 }
                 node = node.Right as WaveletInner;
             }
         } else {
             if (numbits == b + 1) {
                 if (node.Left == null) {
                     var leaf = new WaveletLeaf (node, symbol);
                     // this.Alphabet.Add (leaf);
                     this.Alphabet [symbol] = leaf;
                     node.Left = leaf;
                 } else {
                     (node.Left as WaveletLeaf).Increment ();
                 }
             } else {
                 if (node.Left == null) {
                     node.Left = new WaveletInner (node, true);
                 }
                 node = node.Left as WaveletInner;
             }
         }
     }
 }