bitmap

package
v27.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package bitmap provides a datatype for long vectors of bits.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoBitAvailable is returned when no more bits are available to set
	ErrNoBitAvailable = errors.New("no bit available")
	// ErrBitAllocated is returned when the specific bit requested is already set
	ErrBitAllocated = errors.New("requested bit is already allocated")
)

Functions

This section is empty.

Types

type Bitmap

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

Bitmap is a fixed-length bit vector. It is not safe for concurrent use.

The data is stored as a list of run-length encoded blocks. It operates directly on the encoded representation, without decompressing.

func Copy

func Copy(b *Bitmap) *Bitmap

Copy returns a deep copy of b.

func New

func New(n uint64) *Bitmap

NewHandle returns a new Bitmap of ordinals in the interval [0, n).

func (*Bitmap) Bits

func (h *Bitmap) Bits() uint64

Bits returns the length of the bit sequence

func (*Bitmap) IsSet

func (h *Bitmap) IsSet(ordinal uint64) bool

IsSet atomically checks if the ordinal bit is set. In case ordinal is outside of the bit sequence limits, false is returned.

func (*Bitmap) MarshalBinary

func (h *Bitmap) MarshalBinary() ([]byte, error)

MarshalBinary encodes h into a binary representation.

func (*Bitmap) MarshalJSON

func (h *Bitmap) MarshalJSON() ([]byte, error)

MarshalJSON encodes h into a JSON message

func (*Bitmap) Set

func (h *Bitmap) Set(ordinal uint64) error

Set atomically sets the corresponding bit in the sequence

func (*Bitmap) SetAny

func (h *Bitmap) SetAny(serial bool) (uint64, error)

SetAny sets the first unset bit in the sequence and returns the ordinal of the set bit.

When serial=true, the bitmap is scanned starting from the ordinal following the bit most recently set by Bitmap.SetAny or Bitmap.SetAnyInRange.

func (*Bitmap) SetAnyInRange

func (h *Bitmap) SetAnyInRange(start, end uint64, serial bool) (uint64, error)

SetAnyInRange sets the first unset bit in the range [start, end] and returns the ordinal of the set bit.

When serial=true, the bitmap is scanned starting from the ordinal following the bit most recently set by Bitmap.SetAny or Bitmap.SetAnyInRange.

func (*Bitmap) String

func (h *Bitmap) String() string

func (*Bitmap) UnmarshalBinary

func (h *Bitmap) UnmarshalBinary(ba []byte) error

UnmarshalBinary decodes a binary representation of a Bitmap value which was generated using Bitmap.MarshalBinary.

The scan position for serial Bitmap.SetAny and Bitmap.SetAnyInRange operations is neither unmarshaled nor reset.

func (*Bitmap) UnmarshalJSON

func (h *Bitmap) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes JSON message into h

func (*Bitmap) Unselected

func (h *Bitmap) Unselected() uint64

Unselected returns the number of bits which are not selected

func (*Bitmap) Unset

func (h *Bitmap) Unset(ordinal uint64) error

Unset atomically unsets the corresponding bit in the sequence

Jump to

Keyboard shortcuts

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