public long Decode(IBitStream 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; } } } }
public override IEnumerable<int> ExtractFrom(int start, int count) { var ctx = new BitStreamCtx (); int run_len = this.LocateAt (start - 1, ctx); int v; if (run_len == 0) { v = this.GetNext (ctx); if (v == 1) { run_len = this.GetNext (ctx) - 1; } } else { v = 1; run_len--; } yield return v; for (int i = 1; i < count; i++) { if (run_len > 0) { run_len--; // v = 1; } else { v = this.GetNext (ctx); if (v == 1) { run_len = this.GetNext (ctx) - 1; } } yield return v; } }
/// <summary> /// Initializes a new instance of the <see cref="natix.CompactDS.UnraveledSymbolGolynskiRL"/> class. /// </summary> public UnraveledSymbolGolynskiRL(GolynskiListRL2Seq _seqindex, int _symbol) { this.seqindex = _seqindex; this.symbol = _symbol; this.ctx = new BitStreamCtx (); this.list = this.seqindex.GetPERM ().GetListRL2 ().Diffs; }
public int Decode(IBitStream 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; } } } }
public int Decode(BitStream32 Buffer, BitStreamCtx ctx) { int u = Buffer.ReadZeros (ctx); //int u = Buffer.ReadOnes (); Buffer.Read (ctx); return u; }
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; }
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; } }
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; } }
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; }
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; } }
public int Decode(IBitStream 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; } }
public int Decode(IBitStream 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; }
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; }
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; }
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); } } } }
public long Decode(IBitStream 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); } } } }
public long Decode(IBitStream 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; } }
public ContextListI() { this.ctx = new BitStreamCtx(); this.Reset(); }
public long Decode(BitStream32 stream, BitStreamCtx ctx) { return this.Decode (stream, this.MaxValue, ctx); }
public int GetNext(BitStreamCtx ctx, ref int run_len) { if (run_len > 0) { run_len--; return 1; } var p = this.GetNext (ctx); if (p == 1) { run_len = this.GetNext (ctx) - 1; } return p; }
public void PrintDebug() { var ctx = new BitStreamCtx (); ctx.Seek (0); int i = 0; while (ctx.Offset < this.Stream.CountBits) { var c = this.Coder.Decode (this.Stream, ctx); Console.WriteLine ("=> i: {0}, c: {1}", i, c); } }
public int Sum(int start, int count, BitStreamCtx ctx, ref int run_len) { run_len = this.LocateAt (start - 1, ctx); int sum = this.GetNext (ctx, ref run_len); count--; if (count > 0 && run_len > 0) { sum += run_len; count -= run_len; run_len = 0; } if (count < 0) { sum += count; run_len = -count; return sum; } while (count > 0) { int v = this.GetNext (ctx, ref run_len); sum += v; count--; if (count > 0 && v == 1) { count -= run_len; sum += run_len; if (count < 0) { sum += count; run_len = -count; } else { run_len = 0; } } } return sum; }
protected override int ReadNext(BitStreamCtx ctx) { if (run_len > 0) { run_len--; return 1; } int d = base.ReadNext (ctx); if (d == 1) { run_len = base.ReadNext (ctx) - 1; } return d; }
public int SelectRL(int symbol, int abs_rank, BitStreamCtx ctx, ref int run_len) { if (abs_rank < 1) { return -1; } symbol++; var pos = this.LENS.Select1 (symbol); var rank0 = pos + 1 - symbol; return this.PERM.GetListRL2 ().GetItem (abs_rank + rank0 - 1, ctx, ref run_len); }
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; }
/// <summary> /// Locates ctx at index. Returns the remaining run_len value if any /// </summary> /// <returns> protected int LocateAt(int index, BitStreamCtx ctx) { if (index == -1) { ctx.Seek (0); return 0; } int offset_index = index / this.BlockSize; if (offset_index == 0) { ctx.Seek (0); } else { ctx.Seek (this.Offsets [offset_index - 1]); } int left = 1 + index - offset_index * this.BlockSize; int run_len = 0; for (int i = 0; i < left;) { if (run_len > 0) { // run_len--; i += run_len; run_len = 0; if (left < i) { run_len = i - left; i = left; } } else { var res = this.GetNext (ctx); if (res == 1) { run_len = this.GetNext (ctx) - 1; } i++; } } // Console.WriteLine ("** index: {0}, run_len: {1}, left: {2}", index, run_len, left); return run_len; }
/// <summary> /// Finds the sum or the insertion position of sum. /// </summary> /// <returns> public int FindSum(int start, int sum, BitStreamCtx ctx, ref int run_len) { int rank = 0; run_len = this.LocateAt (start - 1, ctx); int current_sum = this.GetNext (ctx, ref run_len); if (current_sum > sum) { return rank; } current_sum += run_len; rank += run_len; run_len = 0; if (current_sum > sum) { run_len = current_sum - sum; rank -= run_len; return rank; } while (current_sum < sum) { int next_diff = this.GetNext (ctx, ref run_len); current_sum += next_diff; if (current_sum > sum) { break; } rank++; if (current_sum == sum) { break; } current_sum += run_len; rank += run_len; run_len = 0; if (current_sum > sum) { run_len = current_sum - sum; rank -= run_len; break; } } return rank; }
public int Decode(IBitStream Buffer, BitStreamCtx ctx) { return this.Coder.Decode (Buffer, ctx) - this.Smaller; }
public void Build(IBitStream 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.Count ]; 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; } }
public int Decode(IBitStream stream, BitStreamCtx ctx) { return this.Decode (stream, this.Size, ctx); }