bitpack

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 4 Imported by: 3

README

bitpack

Go Reference

A high-performance Go library for bit packing and unpacking integers of various bit widths. Part of the parquet-go ecosystem.

Includes AMD64 assembly optimizations with pure Go fallback for portability.

go get github.com/parquet-go/bitpack

Usage

import "github.com/parquet-go/bitpack"

// Pack int32 values with 3-bit width
values := []int32{1, 2, 3, 4, 5}
bitWidth := uint(3)
packedSize := bitpack.ByteCount(uint(len(values)) * bitWidth)
dst := make([]byte, packedSize+bitpack.PaddingInt32)
bitpack.PackInt32(dst, values, bitWidth)

// Unpack int32 values
unpacked := make([]int32, len(values))
bitpack.UnpackInt32(unpacked, dst, bitWidth)

For complete working examples, see the examples directory.

Documentation

Overview

Package bitpack implements efficient bit packing and unpacking routines for integers of various bit widths.

Index

Constants

View Source
const PaddingInt32 = 16

PaddingInt32 is the padding expected to exist after the end of input buffers for the UnpackInt32 algorithm to avoid reading beyond the end of the input.

View Source
const PaddingInt64 = 32

PaddingInt64 is the padding expected to exist after the end of input buffers for the UnpackInt32 algorithm to avoid reading beyond the end of the input.

Variables

This section is empty.

Functions

func ByteCount

func ByteCount(bitCount uint) int

ByteCount returns the number of bytes needed to hold the given bit count.

func Pack

func Pack[T Int](dst []byte, src []T, bitWidth uint)

Pack packs values from src to dst, each value is packed into the given bit width regardless of how many bits are needed to represent it.

func Unpack

func Unpack[T Int](dst []T, src []byte, bitWidth uint)

Unpack unpacks values from src to dst, each value is unpacked from the given bit width regardless of how many bits are needed to represent it.

Types

type Int

type Int interface {
	~int32 | ~uint32 | ~int64 | ~uint64 | ~int | ~uintptr
}

Int is a type constraint representing the integer types that this package supports.

Directories

Path Synopsis
Package unsafecast exposes functions to bypass the Go type system and perform conversions between types that would otherwise not be possible.
Package unsafecast exposes functions to bypass the Go type system and perform conversions between types that would otherwise not be possible.

Jump to

Keyboard shortcuts

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