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      1   package main
     2      2   
     3      3   import (
            4  +	mtf "0dev.org/encoding/mtf"
     4      5   	iou "0dev.org/ioutil"
     5         -	mtf "0dev.org/mtf"
     6      6   	"fmt"
     7      7   	"io"
     8      8   	"os"
     9      9   )
    10     10   
    11     11   func main() {
    12     12   	var code int

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

    11     11   // 0 - 11, 1 - 110, 2 - 1100, 3 - 1101, 4 - 11000
    12     12   package fibonacci
    13     13   
    14     14   import (
    15     15   	"io"
    16     16   )
    17     17   
           18  +// Alias type with methods for encoding and decoding integers
    18     19   type Numbers []uint64
    19     20   
    20     21   var (
    21     22   	// Used for encoding and decoding byte values
    22     23   	bytesCodec = New(14)
    23     24   )
    24     25   
................................................................................
    75     76   
    76     77   		value >>= 1
    77     78   		length++
    78     79   	}
    79     80   	return result + f[length] - 1, length + 1
    80     81   }
    81     82   
    82         -func Writer(target io.Writer) io.Writer {
           83  +// Returns a fibonacci encoder over the provided io.Writer
           84  +func Encoder(target io.Writer) io.Writer {
    83     85   	var enc encoder
    84     86   	enc.target = target
    85     87   	return &enc
    86     88   }
    87     89   
    88     90   type encoder struct {
    89     91   	target    io.Writer
    90     92   	remaining byte
    91     93   	length    byte
    92     94   }
    93     95   
           96  +// Implements io.Writer
    94     97   func (e *encoder) Write(input []byte) (int, error) {
    95     98   	var (
    96     99   		total int
    97    100   		err   error
    98    101   	)
    99    102   
   100    103   	// Flush on a nil slice
................................................................................
   151    154   
   152    155   		// Account for the processed input byte
   153    156   		total++
   154    157   	}
   155    158   	return total, err
   156    159   }
   157    160   
   158         -func Reader(source io.Reader) io.Reader {
          161  +// Returns a fibonacci decoder over the provided io.Reader
          162  +func Decoder(source io.Reader) io.Reader {
   159    163   	var dec decoder
   160    164   	dec.source = source
   161    165   	return &dec
   162    166   }
   163    167   
   164    168   type decoder struct {
   165    169   	source io.Reader
   166    170   	buffer uint64
   167    171   	at     byte
   168    172   }
   169    173   
          174  +// Implements io.Reader
   170    175   func (d *decoder) Read(output []byte) (int, error) {
   171    176   	var (
   172    177   		total int
   173    178   		err   error
   174    179   	)
   175    180   
   176    181   start:

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

    36     36   		}
    37     37   	}
    38     38   }
    39     39   
    40     40   func TestWriterReader(t *testing.T) {
    41     41   	var (
    42     42   		buf   bytes.Buffer
    43         -		w     io.Writer = Writer(&buf)
           43  +		w     io.Writer = Encoder(&buf)
    44     44   		input []byte    = make([]byte, 256)
    45     45   		fib   Numbers   = New(16)
    46     46   	)
    47     47   
    48     48   	for i := uint64(0); i < 256; i++ {
    49     49   		input[i] = byte(i)
    50     50   	}
................................................................................
    79     79   			t.Fatal("Unexpected location for", i, "value", vs)
    80     80   		}
    81     81   		output = output[len(vs):]
    82     82   	}
    83     83   
    84     84   	var (
    85     85   		in  *bytes.Reader = bytes.NewReader(buf.Bytes())
    86         -		r   io.Reader     = Reader(in)
           86  +		r   io.Reader     = Decoder(in)
    87     87   		out bytes.Buffer
    88     88   	)
    89     89   	io.Copy(&out, r)
    90     90   	decoded := out.Bytes()
    91     91   
    92     92   	delta := diff.Diff(diff.D{Len1: len(decoded), Len2: len(input), EqualFunc: func(i, j int) bool {
    93     93   		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.