Help us shape the future of Go! Take the 2026 Go Developer Survey

chunkenc

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Appender

type Appender interface {
	Append(int64)
	AppendAt(uint16, int64)
}

Appender adds sample pairs to a chunk.

type Chunk

type Chunk interface {
	// Bytes returns the underlying byte slice of the chunk.
	Bytes() []byte

	// Encoding returns the encoding type of the chunk.
	Encoding() Encoding

	// Appender returns an appender to append samples to the chunk.
	Appender() (Appender, error)

	// Iterator returns an iterator that iterates sample by sample.
	// The iterator passed as argument is for re-use.
	// Depending on implementation, the iterator can
	// be re-used or a new iterator can be allocated.
	Iterator(Iterator) Iterator

	// NumSamples returns the number of samples in the chunk.
	NumSamples() int

	// Compact is called whenever a chunk is expected to be complete (no more
	// samples appended) and the underlying implementation can eventually
	// optimize the chunk.
	// There's no strong guarantee that no samples will be appended once
	// Compact() is called. Implementing this function is optional.
	Compact()
}

Chunk holds a sequence of sample pairs that can be iterated over and appended to.

func FromData

func FromData(e Encoding, d []byte) (Chunk, error)

FromData returns a chunk from a byte slice of chunk data. This is there so that users of the library can easily create chunks from bytes.

func FromValuesDelta

func FromValuesDelta(values ...int64) Chunk

FromValuesDelta takes a sequence of values and returns a new populated Chunk. This is mostly helpful in tests.

func FromValuesRLE

func FromValuesRLE(value int64, length uint16) Chunk

FromValuesRLE takes a value and adds it length amounts of times to the Chunk. This is mostly helpful in tests.

func FromValuesXOR

func FromValuesXOR(values ...int64) Chunk

FromValuesXOR takes a sequence of values and returns a new populated Chunk. This is mostly helpful in tests.

func FromValuesXORAt

func FromValuesXORAt(index uint16, value int64) Chunk

FromValuesXORAt inserts a value at the given index in a Chunk. This extra helper is necessary because FromValuesXOR(0,0,3) results in different bytes than FromValuesXORAt(2,3).

type DeltaChunk

type DeltaChunk struct {
	// contains filtered or unexported fields
}

DeltaChunk holds double delta encoded sample data.

func NewDeltaChunk

func NewDeltaChunk() *DeltaChunk

func (*DeltaChunk) Appender

func (c *DeltaChunk) Appender() (Appender, error)

Appender implements the Chunk interface.

func (*DeltaChunk) Bytes

func (c *DeltaChunk) Bytes() []byte

Bytes returns the underlying byte slice of the chunk.

func (*DeltaChunk) Compact

func (c *DeltaChunk) Compact()

func (*DeltaChunk) Encoding

func (c *DeltaChunk) Encoding() Encoding

Encoding returns the encoding type.

func (*DeltaChunk) Iterator

func (c *DeltaChunk) Iterator(it Iterator) Iterator

Iterator implements the Chunk interface.

func (*DeltaChunk) NumSamples

func (c *DeltaChunk) NumSamples() int

NumSamples returns the number of samples in the chunk.

type Encoding

type Encoding uint8

Encoding is the identifier for a chunk encoding.

const (
	EncNone Encoding = iota
	EncXOR
	EncDelta
	EncRLE
)

The different available chunk encodings.

func (Encoding) String

func (e Encoding) String() string

type Iterator

type Iterator interface {
	// Next advances the iterator by one.
	Next() bool
	// Seek advances the iterator forward to the sample at the given index.
	// If current sample found by previous `Next` or `Seek` operation already has this property, Seek has no effect.
	// Seek returns true, if such sample exists, false otherwise.
	// Iterator is exhausted when the Seek returns false.
	Seek(index uint16) bool
	// At returns the current timestamp/value pair.
	// Before the iterator has advanced At behaviour is unspecified.
	At() int64
	// Err returns the current error. It should be used only after iterator is
	// exhausted, that is `Next` or `Seek` returns false.
	Err() error
	// Read returns how many iterations the iterator has read at any given moment.
	Read() uint64
}

Iterator is a simple iterator that can only get the next value. Iterator iterates over the samples of a time series, in timestamp-increasing order.

func NewNopIterator

func NewNopIterator() Iterator

NewNopIterator returns a new chunk iterator that does not hold any data.

type Pool

type Pool interface {
	Put(Chunk) error
	Get(e Encoding, b []byte) (Chunk, error)
}

Pool is used to create and reuse chunk references to avoid allocations.

func NewPool

func NewPool() Pool

NewPool returns a new pool.

type RLEChunk

type RLEChunk struct {
	// contains filtered or unexported fields
}

RLEChunk implements a run-length-encoding chunk that's useful when there are lots of repetitive values stored.

func NewRLEChunk

func NewRLEChunk() *RLEChunk

func (*RLEChunk) Appender

func (c *RLEChunk) Appender() (Appender, error)

func (*RLEChunk) Bytes

func (c *RLEChunk) Bytes() []byte

Bytes returns the underlying byte slice of the chunk.

func (*RLEChunk) Compact

func (c *RLEChunk) Compact()

func (*RLEChunk) Encoding

func (c *RLEChunk) Encoding() Encoding

Encoding returns the encoding type.

func (*RLEChunk) Iterator

func (c *RLEChunk) Iterator(it Iterator) Iterator

func (*RLEChunk) NumSamples

func (c *RLEChunk) NumSamples() int

NumSamples returns the number of samples in the chunk.

func (*RLEChunk) NumValues

func (c *RLEChunk) NumValues() int

type XORChunk

type XORChunk struct {
	// contains filtered or unexported fields
}

XORChunk holds XOR encoded sample data.

func NewXORChunk

func NewXORChunk() *XORChunk

NewXORChunk returns a new chunk with XOR encoding of the given size.

func (*XORChunk) Appender

func (c *XORChunk) Appender() (Appender, error)

Appender implements the Chunk interface.

func (*XORChunk) Bytes

func (c *XORChunk) Bytes() []byte

Bytes returns the underlying byte slice of the chunk.

func (*XORChunk) Compact

func (c *XORChunk) Compact()

func (*XORChunk) Encoding

func (c *XORChunk) Encoding() Encoding

Encoding returns the encoding type.

func (*XORChunk) Iterator

func (c *XORChunk) Iterator(it Iterator) Iterator

Iterator implements the Chunk interface.

func (*XORChunk) NumSamples

func (c *XORChunk) NumSamples() int

NumSamples returns the number of samples in the chunk.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL