compress

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compress is the compressor of the writer: for one chunk of one column, it tries the encodings of internal/encode that fit its type on a sample of the rows, keeps the one that makes the smallest array, and applies it to the whole chunk. The children of an encoding (the codes of a dictionary, the integers of ALP, the lengths of FSST) are compressed the same way, down to a depth of 3, as the reference does (vortex-compressor and vortex-btrblocks).

A candidate is measured by encoding the sample with it, its children included, and counting the bytes of the tree plus an overhead per array and per buffer, so that an encoding that saves less than what it costs to describe is not taken. The plain array is always a candidate, and the result is checked against it on the whole chunk: a chunk is never made larger. The sample is runs of 64 consecutive rows, at least 16 of them and about 1% of the chunk, at offsets drawn from a fixed seed: the same rows always give the same tree. The bytes of a candidate that do not grow with the rows (the symbol table of FSST, the dictionary of OnPair) are charged at the share of the rows its sample holds, and OnPair trains on half of the bytes of a sample rather than 15%, as the reference does since 0.94.0. As there too, a dictionary of strings is measured last, on all the rows, when a probe of whole runs of rows says it may beat the best ratio of the sample (dicttrial.go).

The candidates of a trial (the sample, and the children of its candidates) are the ones the reference does not rule out from the statistics of its rows: integers are not tried as a dictionary when more than half of their valid values are distinct, nor as a sparse array when their most frequent value is under nine tenths of them (and they are not mostly null), and floats are not tried as a dictionary when more than half are distinct. A scheme is never twice in a chain of parents, and some leave out more under some of their children, as the exclusion rules of the reference do (exclZigZag and the others). The values of a frame of reference are bit-packed, as the reference does, with no other candidate. The probe of the dictionary layout keeps the scheme it chose, for the chunk of the same rows that follows it.

A Compressor is not safe for concurrent use: the writer has one per column. Once it has seen chunks of the largest size, it allocates nothing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compressor

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

Compressor holds the memory of the compression of the chunks of a column.

func New

func New(mode Mode) *Compressor

New returns a Compressor.

func NewLimited

func NewLimited(mode Mode, limit Limits) *Compressor

NewLimited returns a Compressor that does without the encodings of limit.

func (*Compressor) Bools

func (c *Compressor) Bools(v, nulls []bool) *encode.Node

Bools is the compressed array of booleans, or nil for the plain array: a constant, or nothing.

func (*Compressor) Configure

func (c *Compressor) Configure(mode Mode, limit Limits)

Configure makes c a Compressor of this mode and of these limits, with the memory it has: the arrays of its earlier calls must not be used any more.

func (*Compressor) Decimals

func (c *Compressor) Decimals(raw []byte, width int, nulls []bool) *encode.Node

Decimals is the compressed array of decimals of width bytes, or nil for the plain array: their byte parts, the integers compressed, when the values fit an i64.

func (*Compressor) Numbers

func (c *Compressor) Numbers(p PType, raw []byte, nulls []bool) *encode.Node

Numbers is the compressed array of the numbers raw of type p, or nil for the plain array.

func (*Compressor) PicksDict

func (c *Compressor) PicksDict(p PType, raw []byte, nulls []bool) bool

PicksDict says whether the compressor would write the numbers raw of type p as a dictionary: the probe of the dictionary layout of the writer.

func (*Compressor) PicksDictStrings

func (c *Compressor) PicksDictStrings(v [][]byte, nulls []bool, utf8 bool) bool

PicksDictStrings is PicksDict for strings.

func (*Compressor) Reset

func (c *Compressor) Reset()

Reset frees the arrays of the earlier calls, which must not be used any more.

func (*Compressor) Strings

func (c *Compressor) Strings(v [][]byte, nulls []bool, utf8 bool) *encode.Node

Strings is the compressed array of the strings v (utf8, else binary), or nil for the plain array.

func (*Compressor) Timestamps

func (c *Compressor) Timestamps(v []int64, nulls []bool, ticks int64) *encode.Node

Timestamps is the compressed array of timestamps in ticks of a second (one of the encode.Ticks constants), or nil for the plain array: their datetime parts, the parts compressed as integers, or the integers themselves when that is smaller.

type Limits

type Limits struct {
	NoRLE      bool // fastlanes.rle
	NoMasked   bool // vortex.masked
	NoSequence bool // vortex.sequence
	NoZstd     bool // vortex.zstd
	NoOnPair   bool // vortex.onpair
	NoPco      bool // vortex.pco
}

Limits lists the encodings that a compressor leaves out, because the edition a file targets does not have them. The zero value leaves out none.

type Mode

type Mode uint8

Mode is the set of encodings the compressor takes.

const (
	// Default is the lightweight encodings.
	Default Mode = iota
	// Compact adds Pco for the numbers wider than 8 bits, and zstd for the numbers and the strings.
	Compact
)

type PType

type PType uint8

PType is the type of the numbers of an array.

const (
	U8 PType = iota
	U16
	U32
	U64
	I8
	I16
	I32
	I64
	F32
	F64
)

The types of numbers.

func (PType) Width

func (p PType) Width() int

Width is the bytes of a number of the type.

Jump to

Keyboard shortcuts

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