Check-in [cb736e7ad3]
Overview
SHA1:cb736e7ad34d3611e2e73ff5ea54e76c5e47cfc0
Date: 2015-01-01 15:19:21
User: spaskalev
Comment:[fibonacci] renamed Writer->Encoder, Reader->Decoder. [mtf] moved package mtf to encoding\mtf
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-01-02
14:35
[98661a7373] Minor optimizations to fibonacci.Encoder (user: spaskalev, tags: trunk)
2015-01-01
15:19
[cb736e7ad3] [fibonacci] renamed Writer->Encoder, Reader->Decoder. [mtf] moved package mtf to encoding\mtf (user: spaskalev, tags: trunk)
15:12
[f1a8d5baa9] Use a common fibonacci number source for each encoder and decoder. Dropped the two-bytes buffer from the encoder struct. (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/commands/mtf/main.go from [b672c1daee] to [8212c2eba2].

1
2
3
4
5
6
7
8
9
10
11
12
package main

import (
	iou "0dev.org/ioutil"
	mtf "0dev.org/mtf"
	"fmt"
	"io"
	"os"
)

func main() {
	var code int



|
|







1
2
3
4
5
6
7
8
9
10
11
12
package main

import (
	mtf "0dev.org/encoding/mtf"
	iou "0dev.org/ioutil"
	"fmt"
	"io"
	"os"
)

func main() {
	var code int

Modified src/0dev.org/encoding/fibonacci/fib.go from [5685c81b13] to [3231551b1f].

11
12
13
14
15
16
17

18
19
20
21
22
23
24
..
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
...
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
// 0 - 11, 1 - 110, 2 - 1100, 3 - 1101, 4 - 11000
package fibonacci

import (
	"io"
)


type Numbers []uint64

var (
	// Used for encoding and decoding byte values
	bytesCodec = New(14)
)

................................................................................

		value >>= 1
		length++
	}
	return result + f[length] - 1, length + 1
}


func Writer(target io.Writer) io.Writer {
	var enc encoder
	enc.target = target
	return &enc
}

type encoder struct {
	target    io.Writer
	remaining byte
	length    byte
}


func (e *encoder) Write(input []byte) (int, error) {
	var (
		total int
		err   error
	)

	// Flush on a nil slice
................................................................................

		// Account for the processed input byte
		total++
	}
	return total, err
}


func Reader(source io.Reader) io.Reader {
	var dec decoder
	dec.source = source
	return &dec
}

type decoder struct {
	source io.Reader
	buffer uint64
	at     byte
}


func (d *decoder) Read(output []byte) (int, error) {
	var (
		total int
		err   error
	)

start:







>







 







>
|











>







 







>
|











>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// 0 - 11, 1 - 110, 2 - 1100, 3 - 1101, 4 - 11000
package fibonacci

import (
	"io"
)

// Alias type with methods for encoding and decoding integers
type Numbers []uint64

var (
	// Used for encoding and decoding byte values
	bytesCodec = New(14)
)

................................................................................

		value >>= 1
		length++
	}
	return result + f[length] - 1, length + 1
}

// Returns a fibonacci encoder over the provided io.Writer
func Encoder(target io.Writer) io.Writer {
	var enc encoder
	enc.target = target
	return &enc
}

type encoder struct {
	target    io.Writer
	remaining byte
	length    byte
}

// Implements io.Writer
func (e *encoder) Write(input []byte) (int, error) {
	var (
		total int
		err   error
	)

	// Flush on a nil slice
................................................................................

		// Account for the processed input byte
		total++
	}
	return total, err
}

// Returns a fibonacci decoder over the provided io.Reader
func Decoder(source io.Reader) io.Reader {
	var dec decoder
	dec.source = source
	return &dec
}

type decoder struct {
	source io.Reader
	buffer uint64
	at     byte
}

// Implements io.Reader
func (d *decoder) Read(output []byte) (int, error) {
	var (
		total int
		err   error
	)

start:

Modified src/0dev.org/encoding/fibonacci/fib_test.go from [33c293fd3b] to [7b29d51e21].

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
		}
	}
}

func TestWriterReader(t *testing.T) {
	var (
		buf   bytes.Buffer
		w     io.Writer = Writer(&buf)
		input []byte    = make([]byte, 256)
		fib   Numbers   = New(16)
	)

	for i := uint64(0); i < 256; i++ {
		input[i] = byte(i)
	}
................................................................................
			t.Fatal("Unexpected location for", i, "value", vs)
		}
		output = output[len(vs):]
	}

	var (
		in  *bytes.Reader = bytes.NewReader(buf.Bytes())
		r   io.Reader     = Reader(in)
		out bytes.Buffer
	)
	io.Copy(&out, r)
	decoded := out.Bytes()

	delta := diff.Diff(diff.D{Len1: len(decoded), Len2: len(input), EqualFunc: func(i, j int) bool {
		return decoded[i] == input[j]







|







 







|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
		}
	}
}

func TestWriterReader(t *testing.T) {
	var (
		buf   bytes.Buffer
		w     io.Writer = Encoder(&buf)
		input []byte    = make([]byte, 256)
		fib   Numbers   = New(16)
	)

	for i := uint64(0); i < 256; i++ {
		input[i] = byte(i)
	}
................................................................................
			t.Fatal("Unexpected location for", i, "value", vs)
		}
		output = output[len(vs):]
	}

	var (
		in  *bytes.Reader = bytes.NewReader(buf.Bytes())
		r   io.Reader     = Decoder(in)
		out bytes.Buffer
	)
	io.Copy(&out, r)
	decoded := out.Bytes()

	delta := diff.Diff(diff.D{Len1: len(decoded), Len2: len(input), EqualFunc: func(i, j int) bool {
		return decoded[i] == input[j]

Name change from src/0dev.org/mtf/mtf.go to src/0dev.org/encoding/mtf/mtf.go.

Name change from src/0dev.org/mtf/mtf_test.go to src/0dev.org/encoding/mtf/mtf_test.go.