bitmap

package
v0.0.0-...-a34a5e8 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap struct {
	// Capacity is the number of bits the bitmap allows to access
	Capacity int
	// contains filtered or unexported fields
}

Bitmap provides a size-limited continuous binary structure, allowing access to individiual bits.

It further provides methods to count the number of 0s and 1s up to a given position, respectively find the position of the i-th 0 and 1.

Under the hood it is implemented as a slice of int64 which grows as required.

func New

func New(size, capacity int) *Bitmap

New initializes a new bitmap.

Capacity specifies the maximum size of the bitmap in bits. Thus the addressable bits will be in the closed interval [0, capacity - 1].

size specifies the size with which the bitmap will be initialized, in bits.

func (*Bitmap) Equal

func (bm *Bitmap) Equal(other *Bitmap) bool

Equal checks whether the length and content of two bitmaps is equal.

It does not compare their capacities, however.

func (*Bitmap) Get

func (bm *Bitmap) Get(bit int) (byte, error)

Get retrieves the value at a given index.

While the returned value is a byte, it will always be either 0 or 1.

An error is returned if the index is invalid.

func (*Bitmap) Rank

func (bm *Bitmap) Rank(val, idx int) (int, error)

Rank returns the number of bits with value val, up to and including position idx.

As an example. Rank(1, 42) would return the number of 1-bits up to and including bit 42.

An error is returned if the index is outside the range of the bitmap, or if val is neither 0 nor 1.

func (*Bitmap) Select

func (bm *Bitmap) Select(val, nth int) (int, error)

Select returns the index of the nth bit of value val.

As an example, Select(0, 13) would return the index of the 13th 0-bit in the bitmap.

An error is returned if there is no nth bit of value val in the bitmap, or if val is neither 0 nor 1.

func (*Bitmap) Set

func (bm *Bitmap) Set(bit int) error

Set sets the bit at a given index to 1.

An error is returned if the index is invalid.

func (Bitmap) String

func (bitmap Bitmap) String() string

String returs a representation of the bitmap's contents as a string of bits.

This means that each stored bit will be encoded as either a 0 or 1 ASCII character. Eight bits are grouped together, with 8 bytes per line. The output also contains decimal bit offsets per line.

func (*Bitmap) Unset

func (bm *Bitmap) Unset(bit int) error

Unset sets the bit at a given index to 0.

An error is returned if the index is invalid.

Jump to

Keyboard shortcuts

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