encoding

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MaxVarLen64 = 9
)

Variables

View Source
var (
	FlagTypeIndexMapping  = FlagType{0b10}
	FlagTypePositiveStore = FlagType{0b01}
	FlagTypeNegativeStore = FlagType{0b11}

	// Encodes the count of the zero bin.
	// Encoding format:
	// - [byte] flag
	// - [varfloat64] count of the zero bin
	FlagZeroCountVarFloat = NewFlag(flagTypeSketchFeatures, newSubFlag(1))

	// Encode the total count.
	// Encoding format:
	// - [byte] flag
	// - [varfloat64] total count
	FlagCount = NewFlag(flagTypeSketchFeatures, newSubFlag(0x28))

	// Encode the summary statistics.
	// Encoding format:
	// - [byte] flag
	// - [float64LE] summary stat
	FlagSum = NewFlag(flagTypeSketchFeatures, newSubFlag(0x21))
	FlagMin = NewFlag(flagTypeSketchFeatures, newSubFlag(0x22))
	FlagMax = NewFlag(flagTypeSketchFeatures, newSubFlag(0x23))

	// Encodes log-like index mappings, specifying the base (gamma) and the index offset
	// The subflag specifies the interpolation method.
	// Encoding format:
	// - [byte] flag
	// - [float64LE] gamma
	// - [float64LE] index offset
	FlagIndexMappingBaseLogarithmic = NewFlag(FlagTypeIndexMapping, newSubFlag(0))
	FlagIndexMappingBaseLinear      = NewFlag(FlagTypeIndexMapping, newSubFlag(1))
	FlagIndexMappingBaseQuadratic   = NewFlag(FlagTypeIndexMapping, newSubFlag(2))
	FlagIndexMappingBaseCubic       = NewFlag(FlagTypeIndexMapping, newSubFlag(3))
	FlagIndexMappingBaseQuartic     = NewFlag(FlagTypeIndexMapping, newSubFlag(4))

	// Encodes N bins, each one with its index and its count.
	// Indexes are delta-encoded.
	// Encoding format:
	// - [byte] flag
	// - [uvarint64] number of bins N
	// - [varint64] index of first bin
	// - [varfloat64] count of first bin
	// - [varint64] difference between the index of the second bin and the index
	// of the first bin
	// - [varfloat64] count of second bin
	// - ...
	// - [varint64] difference between the index of the N-th bin and the index
	// of the (N-1)-th bin
	// - [varfloat64] count of N-th bin
	BinEncodingIndexDeltasAndCounts = newSubFlag(1)

	// Encodes N bins whose counts are each equal to 1.
	// Indexes are delta-encoded.
	// Encoding format:
	// - [byte] flag
	// - [uvarint64] number of bins N
	// - [varint64] index of first bin
	// - [varint64] difference between the index of the second bin and the index
	// of the first bin
	// - ...
	// - [varint64] difference between the index of the N-th bin and the index
	// of the (N-1)-th bin
	BinEncodingIndexDeltas = newSubFlag(2)

	// Encodes N contiguous bins, specifiying the count of each one
	// Encoding format:
	// - [byte] flag
	// - [uvarint64] number of bins N
	// - [varint64] index of first bin
	// - [varint64] difference between two successive indexes
	// - [varfloat64] count of first bin
	// - [varfloat64] count of second bin
	// - ...
	// - [varfloat64] count of N-th bin
	BinEncodingContiguousCounts = newSubFlag(3)
)

Functions

func DecodeFloat64LE

func DecodeFloat64LE(b *[]byte) (float64, error)

DecodeFloat64LE deserializes 64-bit floating-point values that have been encoded with EncodeFloat64LE.

func DecodeUvarint64

func DecodeUvarint64(b *[]byte) (uint64, error)

DecodeUvarint64 deserializes 64-bit unsigned integers that have been encoded using EncodeUvarint64.

func DecodeVarfloat64

func DecodeVarfloat64(b *[]byte) (float64, error)

DecodeVarfloat64 deserializes 64-bit floating-point values that have been encoded with EncodeVarfloat64.

func DecodeVarint32

func DecodeVarint32(b *[]byte) (int32, error)

DecodeVarint32 deserializes 32-bit signed integers that have been encoded using EncodeVarint64.

func DecodeVarint64

func DecodeVarint64(b *[]byte) (int64, error)

DecodeVarint64 deserializes 64-bit signed integers that have been encoded using EncodeVarint32.

func EncodeFlag

func EncodeFlag(b *[]byte, f Flag)

EncodeFlag encodes a flag and appends its content to the provided []byte.

func EncodeFloat64LE

func EncodeFloat64LE(b *[]byte, v float64)

EncodeFloat64LE serializes 64-bit floating-point values, starting with the least significant bytes.

func EncodeUvarint64

func EncodeUvarint64(b *[]byte, v uint64)

EncodeUvarint64 serializes 64-bit unsigned integers 7 bits at a time, starting with the least significant bits. The most significant bit in each output byte is the continuation bit and indicates whether there are additional non-zero bits encoded in following bytes. There are at most 9 output bytes and the last one does not have a continuation bit, allowing for it to encode 8 bits (8*7+8 = 64).

func EncodeVarfloat64

func EncodeVarfloat64(b *[]byte, v float64)

EncodeVarfloat64 serializes 64-bit floating-point values using a method that is similar to the varuint encoding and that is space-efficient for non-negative integer values. The output takes at most 9 bytes. Input values are first shifted as floating-point values (+1), then transmuted to integer values, then shifted again as integer values (-Float64bits(1)). That is in order to minimize the number of non-zero bits when dealing with non-negative integer values. After that transformation, any input integer value no greater than 2^53 (the largest integer value that can be encoded exactly as a 64-bit floating-point value) will have at least 6 leading zero bits. By rotating bits to the left, those bits end up at the right of the binary representation. The resulting bits are then encoded similarly to the varuint method, but starting with the most significant bits.

func EncodeVarint64

func EncodeVarint64(b *[]byte, v int64)

EncodeVarint64 serializes 64-bit signed integers using zig-zag encoding, which ensures small-scale integers are turned into unsigned integers that have leading zeros, whether they are positive or negative, hence allows for space-efficient varuint encoding of those values.

func Uvarint64Size added in v1.2.1

func Uvarint64Size(v uint64) int

Uvarint64Size returns the number of bytes that EncodeUvarint64 encodes a 64-bit unsigned integer into.

func Varfloat64Size added in v1.2.1

func Varfloat64Size(v float64) int

Varfloat64Size returns the number of bytes that EncodeVarfloat64 encodes a 64-bit floating-point value into.

func Varint64Size added in v1.2.1

func Varint64Size(v int64) int

Varint64Size returns the number of bytes that EncodeVarint64 encodes a 64-bit signed integer into.

Types

type Flag

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

func DecodeFlag

func DecodeFlag(b *[]byte) (Flag, error)

DecodeFlag decodes a flag and updates the provided []byte so that it starts immediately after the encoded flag.

func NewFlag

func NewFlag(t FlagType, s SubFlag) Flag

func (Flag) SubFlag

func (f Flag) SubFlag() SubFlag

func (Flag) Type

func (f Flag) Type() FlagType

type FlagType

type FlagType struct {
	// contains filtered or unexported fields

} // mask: 0b00000011

type SubFlag

type SubFlag struct {
	// contains filtered or unexported fields

} // mask: 0b11111100

Jump to

Keyboard shortcuts

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