Index: src/0dev.org/encoding/mtf/mtf.go ================================================================== --- src/0dev.org/encoding/mtf/mtf.go +++ src/0dev.org/encoding/mtf/mtf.go @@ -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 } } } } Index: src/0dev.org/encoding/mtf/mtf_test.go ================================================================== --- src/0dev.org/encoding/mtf/mtf_test.go +++ src/0dev.org/encoding/mtf/mtf_test.go @@ -22,8 +22,8 @@ processed := output.Bytes() delta := diff.Diff(diff.D{Len1: len(data), Len2: len(processed), EqualFunc: func(i, j int) bool { return data[i] == processed[j] }}) if len(delta.Added) > 0 || len(delta.Removed) > 0 { - t.Error("Differences detected ", delta) + t.Error("Differences detected ", delta, processed) } }