func compress(from []byte) []byte { const ( order = 3 mixer = 0xff51afd7ed558ccd nbits = 12 ) var ( ctrl = 0 bit = 128 loc = 0 to = []byte{0} ctx = uint64(0) lut [1 << nbits]byte ) for _, next := range from { hash := ctx * mixer hash >>= 64 - nbits pred := lut[hash] if pred == next { ctrl += bit } else { lut[hash] = next to = append(to, next) } if bit >>= 1; bit == 0 { to[loc] = byte(ctrl) ctrl = 0 bit = 128 loc = len(to) } ctx <<= 8 ctx += uint64(next) ctx &= 1<<(order*8) - 1 } to[loc] = byte(ctrl) return to }
To receive a hint, submit unfixed code.