bitmap

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 1 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 {
	// contains filtered or unexported fields
}

Bitmap is a structure holding a bitmap

func FromBytes

func FromBytes(b []byte) *Bitmap

FromBytes create a bitmap struct from bytes

func NewBits

func NewBits(nBits int) *Bitmap

NewBits creates a new bitmap that can address nBits entries. All bits are initially 0 (free).

func NewBytes

func NewBytes(nbytes int) *Bitmap

NewBytes creates a new bitmap of size bytes; it is not in bits to force the caller to have a complete set

func (*Bitmap) Clear

func (bm *Bitmap) Clear(location int) error

Clear a specific bit location

func (*Bitmap) FirstFree

func (bm *Bitmap) FirstFree(start int) int

FirstFree returns the first free bit in the bitmap Begins at start, so if you want to find the first free bit, pass start=1. Returns -1 if none found.

func (*Bitmap) FirstSet

func (bm *Bitmap) FirstSet() int

FirstSet returns location of first set bit in the bitmap

func (*Bitmap) FreeList

func (bm *Bitmap) FreeList() []Contiguous

FreeList returns a slicelist of contiguous free locations by location. It is sorted by location. If you want to sort it by size, uses sort.Slice for example, if the bitmap is 10010010 00100000 10000010, it will return

	 1: 2, // 2 free bits at position 1
	 4: 2, // 2 free bits at position 4
	 8: 3, // 3 free bits at position 8
	11: 5  // 5 free bits at position 11
    17: 5  // 5 free bits at position 17
	23: 1, // 1 free bit at position 23

if you want it in reverse order, just reverse the slice.

func (*Bitmap) FromBytes

func (bm *Bitmap) FromBytes(b []byte)

FromBytes overwrite the existing map with the contents of the bytes. It is the equivalent of BitmapFromBytes, but uses an existing Bitmap.

func (*Bitmap) IsSet

func (bm *Bitmap) IsSet(location int) (bool, error)

IsSet check if a specific bit location is set

func (*Bitmap) Set

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

Set a specific bit location

func (*Bitmap) ToBytes

func (bm *Bitmap) ToBytes() []byte

ToBytes returns raw bytes underlying the bitmap

type Contiguous

type Contiguous struct {
	Position int
	Count    int
}

Contiguous a position and count of contiguous bits, either free or set

Jump to

Keyboard shortcuts

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