Check-in [3ea011cf07]
Overview
Comment:Use for range in mtf's encoder for the position table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3ea011cf07938f5ec605e43ea957f6135dd47e57
User & Date: spaskalev on 2015-01-14 20:46:02
Other Links: manifest | tags
Context
2015-01-26
20:30
Added tbd from gophergala/tbd :) check-in: 61b0c5b57a user: spaskalev tags: trunk
2015-01-14
20:46
Use for range in mtf's encoder for the position table. check-in: 3ea011cf07 user: spaskalev tags: trunk
2015-01-11
08:44
Switched encoding/fibonacci.Encoder back to using a 2-bytes array as a preallocated write buffer. It seems that it otherwise escapes everytime and calls a causes a lot of allocations and subsequent gc work. check-in: 90877fa64f user: spaskalev tags: trunk
Changes

Modified src/0dev.org/encoding/mtf/mtf.go from [76460f96cb] to [f784336e1a].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

type context struct {
	table [256]byte
}

// Encodes data in place
func (c *context) encode(data []byte) {
	for index, value := range data {
		// Loop over the MTF table
		for i := byte(0); i <= 255; i++ {
			if c.table[i] == value {
				// Output the value
				data[index] = i

				// Shift the table
				copy(c.table[1:], c.table[:i])

				// Restore the value in front and break
				c.table[0] = value
				break
			}
		}
	}
}

// Decode data in place







|

|
|

|


|


|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

type context struct {
	table [256]byte
}

// Encodes data in place
func (c *context) encode(data []byte) {
	for dataIndex, dataValue := range data {
		// Loop over the MTF table
		for tableIndex, tableValue := range c.table {
			if tableValue == dataValue {
				// Output the value
				data[dataIndex] = byte(tableIndex)

				// Shift the table
				copy(c.table[1:], c.table[:tableIndex])

				// Restore the value in front and break
				c.table[0] = dataValue
				break
			}
		}
	}
}

// Decode data in place

Modified src/0dev.org/encoding/mtf/mtf_test.go from [74a3c46eb8] to [7051812004].

20
21
22
23
24
25
26
27
28
29

	io.Copy(&output, decoder)
	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)
	}
}







|


20
21
22
23
24
25
26
27
28
29

	io.Copy(&output, decoder)
	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, processed)
	}
}