bitutils

package
v8.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 8 more Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMultipleOf64

func IsMultipleOf64(v int64) bool

IsMultipleOf64 returns whether v is a multiple of 64.

func LeastSignificantBitMask

func LeastSignificantBitMask(index int64) uint64

LeastSignificantBitMask returns a bit mask to return the least significant bits for a value starting from the bit index passed in. ie: if you want a mask for the 4 least significant bits, you call LeastSignificantBitMask(4)

func VisitSetBitRuns

func VisitSetBitRuns(bitmap []byte, bitmapOffset int64, length int64, visitFn VisitFn) error

VisitSetBitRuns is just a convenience function for calling NewSetBitRunReader and then VisitSetBitRuns

Types

type BitRun

type BitRun struct {
	Len int64
	Set bool
}

BitRun represents a run of bits with the same value of length Len with Set representing if the group of bits were 1 or 0.

func (BitRun) String

func (b BitRun) String() string

type BitRunReader

type BitRunReader interface {
	NextRun() BitRun
}

BitRunReader is an interface that is usable by multiple callers to provide multiple types of bit run readers such as a reverse reader and so on.

It's a convenience interface for counting contiguous set/unset bits in a bitmap. In places where BitBlockCounter can be used, then it would be preferred to use that as it would be faster than using BitRunReader.

func NewBitRunReader

func NewBitRunReader(bitmap []byte, offset int64, length int64) BitRunReader

NewBitRunReader returns a reader for the given bitmap, offset and length that grabs runs of the same value bit at a time for easy iteration.

type SetBitRun

type SetBitRun struct {
	Pos    int64
	Length int64
}

SetBitRun describes a run of contiguous set bits in a bitmap with Pos being the starting position of the run and Length being the number of bits.

func (SetBitRun) AtEnd

func (s SetBitRun) AtEnd() bool

AtEnd returns true if this bit run is the end of the set by checking that the length is 0.

func (SetBitRun) Equal

func (s SetBitRun) Equal(rhs SetBitRun) bool

Equal returns whether rhs is the same run as s

type SetBitRunReader

type SetBitRunReader interface {
	// NextRun will return the next run of contiguous set bits in the bitmap
	NextRun() SetBitRun
	// Reset allows re-using the reader by providing a new bitmap, offset and length. The arguments
	// match the New function for the reader being used.
	Reset([]byte, int64, int64)
	// VisitSetBitRuns calls visitFn for each set in a loop starting from the current position
	// it's roughly equivalent to simply looping, calling NextRun and calling visitFn on the run
	// for each run.
	VisitSetBitRuns(visitFn VisitFn) error
}

SetBitRunReader is an interface for reading groups of contiguous set bits from a bitmap. The interface allows us to create different reader implementations that share the same interface easily such as a reverse set reader.

func NewReverseSetBitRunReader

func NewReverseSetBitRunReader(validBits []byte, startOffset, numValues int64) SetBitRunReader

NewReverseSetBitRunReader returns a SetBitRunReader like NewSetBitRunReader, except it will return runs starting from the end of the bitmap until it reaches startOffset rather than starting at startOffset and reading from there. The SetBitRuns will still operate the same, so Pos will still be the position of the "left-most" bit of the run or the "start" of the run. It just returns runs starting from the end instead of starting from the beginning.

func NewSetBitRunReader

func NewSetBitRunReader(validBits []byte, startOffset, numValues int64) SetBitRunReader

NewSetBitRunReader returns a SetBitRunReader for the bitmap starting at startOffset which will read numvalues bits.

type VisitFn

type VisitFn func(pos int64, length int64) error

VisitFn is a callback function for visiting runs of contiguous bits

Jump to

Keyboard shortcuts

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