bits

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotPowerOfTwo = errors.New("size must be a power of two")

ErrNotPowerOfTwo is returned when the size of the bitset is not a power of two.

Functions

This section is empty.

Types

type Bits

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

Bits is a simple bitset implementation, which is a fixed-size array of bits. It supports setting, clearing, and checking the value of a bit at a given position. It also supports counting the number of 1s in the bitset and shifting all bits to the left or right.

func NewBits

func NewBits(size int) (*Bits, error)

NewBits creates a new bitset with the given size.

func (*Bits) ClearBit

func (b *Bits) ClearBit(pos int)

ClearBit clears the bit at the given position to 0.

func (*Bits) CountOnes

func (b *Bits) CountOnes() int

CountOnes calculates the number of bits set to 1 in the bitset.

func (*Bits) IsBitSet

func (b *Bits) IsBitSet(pos int) bool

IsBitSet checks if the bit at the given position is set to 1.

func (*Bits) LeftShift

func (b *Bits) LeftShift(n int)

LeftShift left shifts the entire bitset by n positions.

func (*Bits) RightShift

func (b *Bits) RightShift(n int)

RightShift right shifts the entire bitset by n positions.

func (*Bits) SetBit

func (b *Bits) SetBit(pos int)

SetBit sets the bit at the given position to 1.

Jump to

Keyboard shortcuts

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