(bit uint, prob P)
| 14 | } |
| 15 | |
| 16 | func (enc *Encoder) Encode(bit uint, prob P) { |
| 17 | x := prob.midpoint32(enc.lo, enc.hi) |
| 18 | |
| 19 | if bit == 1 { |
| 20 | enc.hi = x |
| 21 | } else { |
| 22 | enc.lo = x + 1 |
| 23 | } |
| 24 | |
| 25 | for enc.lo^enc.hi < 1<<24 { |
| 26 | enc.data = append(enc.data, byte(enc.lo>>24)) |
| 27 | enc.lo <<= 8 |
| 28 | enc.hi = enc.hi<<8 | 0xFF |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func (enc *Encoder) Close() { |
| 33 | for i := 0; i < 4; i++ { |