Skip to content

Commit

Permalink
Fix additional PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Dec 21, 2018
1 parent 67b4ca0 commit 2ca3a6c
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 58 deletions.
2 changes: 0 additions & 2 deletions encoding/delta_int_encode.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
bitstream "github.com/dgryski/go-bitstream"
)

// ForwardIntIterator allows iterating over a stream of int.

func encodeDeltaInt(
bitWriter *bitstream.BitWriter,
bitsPerEncodedValue int64,
Expand Down
2 changes: 0 additions & 2 deletions encoding/delta_time_encode.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
bitstream "github.com/dgryski/go-bitstream"
)

// ForwardTimeIterator allows iterating over a stream of int64.

func encodeDeltaTime(
bitWriter *bitstream.BitWriter,
bitsPerEncodedValue int64,
Expand Down
10 changes: 10 additions & 0 deletions encoding/math.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package encoding

import "time"

func intSubIntFn(v, v2 int) int {
return v - v2
}
Expand All @@ -19,3 +21,11 @@ func int64AddIntFn(v int64, v2 int) int64 {
func int64SubInt64Fn(v, v2 int64) int {
return int(v - v2)
}

func scaleDownFn(v int64, resolution time.Duration) int64 {
return v / int64(resolution)
}

func scaleUpFn(v int64, resolution time.Duration) int64 {
return v * int64(resolution)
}
2 changes: 0 additions & 2 deletions encoding/run_length_encode_bool.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import (
// writeValueFn reads a bool from an `io.Reader`.
type writeValueFn func(writer io.Writer, value bool) error

// ForwardBoolIterator allows iterating over a stream of bool.

// runLengthEncodeBool run length encodes a stream of bool.
func runLengthEncodeBool(
writer io.Writer,
Expand Down
16 changes: 0 additions & 16 deletions encoding/template/delta_encode.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
package template

import (
"io"

bitstream "github.com/dgryski/go-bitstream"
"github.com/mauricelam/genny/generic"
)

// GenericValue represents a generic value type.
type GenericValue generic.Type

// ForwardValueIterator allows iterating over a stream of GenericValue.
type ForwardValueIterator interface {
generic.Type
io.Closer
Next() bool
Err() error
Current() GenericValue
Rewind()
}

func encodeDeltaValue(
bitWriter *bitstream.BitWriter,
bitsPerEncodedValue int64,
Expand Down
19 changes: 19 additions & 0 deletions encoding/template/generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package template

import (
"io"

"github.com/mauricelam/genny/generic"
)

// GenericValue is a generic type.
type GenericValue generic.Type

// ForwardValueIterator allows iterating over a stream of GenericValue.
type ForwardValueIterator interface {
generic.Type
io.Closer
Next() bool
Err() error
Current() GenericValue
}
12 changes: 6 additions & 6 deletions encoding/template/run_length_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ var (
errNonPositiveNumberOfRepetitions = errors.New("non positive number of repetitions")
)

// readValueFn reads a GenericRLValue from an `io.Reader`.
type readValueFn func(reader io.Reader) (GenericRLValue, error)
// readValueFn reads a GenericValue from an `io.Reader`.
type readValueFn func(reader io.Reader) (GenericValue, error)

// runLengthDecodeValue run length decodes a stream of GenericRLValues.
// runLengthDecodeValue run length decodes a stream of GenericValues.
func runLengthDecodeValue(
reader io.Reader,
readValueFn readValueFn,
) *RunLengthValueIterator {
return newValueIterator(reader, readValueFn)
}

// RunLengthValueIterator iterates over a run length encoded stream of GenericRLValue data.
// RunLengthValueIterator iterates over a run length encoded stream of GenericValue data.
type RunLengthValueIterator struct {
reader io.Reader
readValueFn readValueFn
curr GenericRLValue
curr GenericValue
repetitions int64
closed bool
err error
Expand Down Expand Up @@ -61,7 +61,7 @@ func (rl *RunLengthValueIterator) Next() bool {
}

// Current returns the current string.
func (rl *RunLengthValueIterator) Current() GenericRLValue { return rl.curr }
func (rl *RunLengthValueIterator) Current() GenericValue { return rl.curr }

// Err returns any error recorded while iterating.
func (rl *RunLengthValueIterator) Err() error { return rl.err }
Expand Down
26 changes: 6 additions & 20 deletions encoding/template/run_length_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,25 @@ import (
"encoding/binary"
"io"

"github.com/mauricelam/genny/generic"
"github.com/xichen2020/eventdb/x/bytes"
)

// GenericRLValue is a generic type.
type GenericRLValue generic.Type
// writeValueFn reads a GenericValue from an `io.Reader`.
type writeValueFn func(writer io.Writer, value GenericValue) error

// writeValueFn reads a GenericRLValue from an `io.Reader`.
type writeValueFn func(writer io.Writer, value GenericRLValue) error

// ForwardRLValueIterator allows iterating over a stream of GenericRLValue.
type ForwardRLValueIterator interface {
generic.Type

io.Closer
Next() bool
Err() error
Current() GenericRLValue
}

// runLengthEncodeValue run length encodes a stream of GenericRLValue.
// runLengthEncodeValue run length encodes a stream of GenericValue.
func runLengthEncodeValue(
writer io.Writer,
extBuf *[]byte, // extBuf is an external byte buffer for memory re-use.
writeValueFn writeValueFn,
valuesIt ForwardRLValueIterator,
valuesIt ForwardValueIterator,
) error {
// Ensure that our buffer size is large enough to handle varint ops.
*extBuf = bytes.EnsureBufferSize(*extBuf, binary.MaxVarintLen64, bytes.DontCopyData)

var (
firstTime = true
last GenericRLValue
last GenericValue
repetitions = 1
)
for valuesIt.Next() {
Expand Down Expand Up @@ -73,7 +59,7 @@ func writeRLE(
writer io.Writer,
extBuf []byte, // extBuf is an external byte buffer for memory re-use.
writeValueFn writeValueFn,
value GenericRLValue,
value GenericValue,
repetitions int,
) error {
// Encode the final value.
Expand Down
6 changes: 1 addition & 5 deletions encoding/time_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,5 @@ func (dec *TimeDec) decodeDelta() (*scaledTimeIterator, error) {
default:
return nil, fmt.Errorf("resolution (%v) is not a valid resolution", resolution)
}
return newScaledTimeIterator(resolution, deltaIter, dec.scaleUpFn), nil
}

func (dec *TimeDec) scaleUpFn(v int64, resolution time.Duration) int64 {
return v * int64(resolution)
return newScaledTimeIterator(resolution, deltaIter, scaleUpFn), nil
}
6 changes: 1 addition & 5 deletions encoding/time_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,10 @@ func (enc *TimeEnc) Encode(
}

// Only delta encoding for now.
return encodeDeltaTime(enc.bitWriter, enc.metaProto.BitsPerEncodedValue, newScaledTimeIterator(opts.Resolution, valuesIt, enc.scaleDownFn), int64SubInt64Fn)
return encodeDeltaTime(enc.bitWriter, enc.metaProto.BitsPerEncodedValue, newScaledTimeIterator(opts.Resolution, valuesIt, scaleDownFn), int64SubInt64Fn)
}

func (enc *TimeEnc) reset(writer io.Writer) {
enc.bitWriter.Reset(writer)
enc.metaProto.Reset()
}

func (enc *TimeEnc) scaleDownFn(v int64, resolution time.Duration) int64 {
return v / int64(resolution)
}

0 comments on commit 2ca3a6c

Please sign in to comment.