(prob P)
| 58 | } |
| 59 | |
| 60 | func (dec *Decoder) Decode(prob P) (bit uint) { |
| 61 | x := prob.midpoint32(dec.lo, dec.hi) |
| 62 | |
| 63 | if dec.code <= x { |
| 64 | dec.hi = x |
| 65 | bit = 1 |
| 66 | } else { |
| 67 | dec.lo = x + 1 |
| 68 | bit = 0 |
| 69 | } |
| 70 | |
| 71 | for dec.lo^dec.hi < 1<<24 { |
| 72 | dec.code = dec.code<<8 | uint32(dec.data[dec.read]) |
| 73 | dec.read++ |
| 74 | dec.lo <<= 8 |
| 75 | dec.hi = dec.hi<<8 | 0xff |
| 76 | } |
| 77 | |
| 78 | return bit |
| 79 | } |