Check-in [5c9c0a2164]
Overview
Comment:encoding/mtf optimizations
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5c9c0a2164ec08b6bb7d2f5fa5ca42dc45a6588a
User & Date: spaskalev on 2015-01-10 21:28:17
Other Links: manifest | tags
Context
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
2015-01-10
21:28
encoding/mtf optimizations check-in: 5c9c0a2164 user: spaskalev tags: trunk
2015-01-04
16:45
Use a lookup table for fibonacci's encoding of bytes. check-in: 9ded78a659 user: spaskalev tags: trunk
Changes

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

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
type context struct {
	table [256]byte
}

// Encodes data in place
func (c *context) encode(data []byte) {
	for index, value := range data {

		// Shortcut for sequential, equal values
		if c.table[0] == value {
			data[index] = 0
			continue
		}

		// Loop over the MTF table
		for j := byte(1); j != 0; j++ {
			if c.table[j] == value {
				// Output the value
				data[index] = j

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

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

// Decode data in place
func (c *context) decode(data []byte) {
	for index, value := range data {
		position := value

		// Shortcut for sequential, equal values
		if position == 0 {
			data[index] = c.table[0]
			continue
		}

		// Output the value
		data[index] = c.table[position]

		// Shift the table and restore the value in front
		copy(c.table[1:], c.table[:position])
		c.table[0] = data[index]
	}







<
<
<
<
<
<
<

|
|

|


|














<
<
<
<
<
<







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
53
54
55
56






57
58
59
60
61
62
63
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
func (c *context) decode(data []byte) {
	for index, value := range data {
		position := value







		// Output the value
		data[index] = c.table[position]

		// Shift the table and restore the value in front
		copy(c.table[1:], c.table[:position])
		c.table[0] = data[index]
	}