simple8b

package
v1.11.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 4 Imported by: 5

Documentation

Overview

Package simple8b implements the 64bit integer encoding algorithm as published by Ann and Moffat in "Index compression using 64-bit words", Softw. Pract. Exper. 2010; 40:131–147

It is capable of encoding multiple integers with values betweeen 0 and to 1^60 -1, in a single word.

Imported from github.com/jwilder/encoding

Index

Constants

View Source
const MaxValue = (1 << 60) - 1
View Source
const (
	S8B_BIT_SIZE = 60
)

Variables

View Source
var (
	ErrValueOutOfBounds = errors.New("value out of bounds")
)

Functions

func Count

func Count(v uint64) (int, error)

Count returns the number of integers encoded within an uint64

func CountBytes

func CountBytes(b []byte) (int, error)

Count returns the number of integers encoded in the byte slice

func CountBytesBetween

func CountBytesBetween(b []byte, min, max uint64) (int, error)

func Decode

func Decode(dst *[240]uint64, v uint64) (n int, err error)

func DecodeAll

func DecodeAll(dst, src []uint64) (value int, err error)

Decode writes the uncompressed values from src to dst. It returns the number of values written or an error. nocheckptr while the underlying struct layout doesn't change

func DecodeBytesBigEndian

func DecodeBytesBigEndian(dst []uint64, src []byte) (value int, err error)

DecodeBytesBigEndian writes the compressed, big-endian values from src to dst. It returns the number of values written or an error. nocheckptr while the underlying struct layout doesn't change

func Encode

func Encode(src []uint64) (value uint64, n int, err error)

Encode packs as many values into a single uint64. It returns the packed uint64, how many values from src were packed, or an error if the values exceed the maximum value range.

func EncodeAll

func EncodeAll(src []uint64) ([]uint64, error)

Encode returns a packed slice of the values from src. If a value is over 1 << 60, an error is returned. The input src is modified to avoid extra allocations. If you need to re-use, use a copy.

func ForEach

func ForEach(b []byte, fn func(v uint64) bool) error

Types

type Decoder

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

Decoder converts a compressed byte slice to a stream of unsigned 64bit integers.

func NewDecoder

func NewDecoder(b []byte) *Decoder

NewDecoder returns a Decoder from a byte slice

func (*Decoder) Next

func (d *Decoder) Next() bool

Next returns true if there are remaining values to be read. Successive calls to Next advance the current element pointer.

func (*Decoder) Read

func (d *Decoder) Read() uint64

Read returns the current value. Successive calls to Read return the same value.

func (*Decoder) SetBytes

func (d *Decoder) SetBytes(b []byte)

type Encoder

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

Encoder converts a stream of unsigned 64bit integers to a compressed byte slice.

func NewEncoder

func NewEncoder() *Encoder

NewEncoder returns an Encoder able to convert uint64s to compressed byte slices

func (*Encoder) Bytes

func (e *Encoder) Bytes() ([]byte, error)

func (*Encoder) Reset

func (e *Encoder) Reset()

func (*Encoder) SetValues

func (e *Encoder) SetValues(v []uint64)

func (*Encoder) Write

func (e *Encoder) Write(v uint64) error

Jump to

Keyboard shortcuts

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