@@ -29,22 +29,22 @@ table [256]byte } // Encodes data in place func (c *context) encode(data []byte) { - for index, value := range data { + for dataIndex, dataValue := range data { // Loop over the MTF table - for i := byte(0); i <= 255; i++ { - if c.table[i] == value { + for tableIndex, tableValue := range c.table { + if tableValue == dataValue { // Output the value - data[index] = i + data[dataIndex] = byte(tableIndex) // Shift the table - copy(c.table[1:], c.table[:i]) + copy(c.table[1:], c.table[:tableIndex]) // Restore the value in front and break - c.table[0] = value + c.table[0] = dataValue break } } } }