bitset

package
v0.0.0-...-9899634 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNumBits = 64
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet

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

BitSet represents a vector of bits that grows as needed.

func FromBytes

func FromBytes(bytes []byte) *BitSet

FromBytes returns new BitSet containing all the bits in the given byte array.

func New

func New(opts ...Option) *BitSet

New creates a BitSet whose initial size is large enough to explicitly represent bits with indices in the range 0 through NumBits-1. If no configuration is used the DefaultNumBits is used as the number of bits. All bits are initially false.

func (*BitSet) All

func (b *BitSet) All() iter.Seq[int]

func (*BitSet) Clear

func (b *BitSet) Clear(bit int)

Clear sets the bit specified by the index to false.

func (*BitSet) Flip

func (b *BitSet) Flip()

Flip sets each bit to the complement of its current value. This call is equivalent to b.FlipRange(0, b.Size())

func (*BitSet) FlipRange

func (b *BitSet) FlipRange(start int, end int)

FlipRange sets each bit from the specified start bit (inclusive) to the specified end bit (exclusive) to the complement of its current value.

func (*BitSet) Get

func (b *BitSet) Get(bit int) bool

Get returns the value of the bit with the specified index.

func (*BitSet) Length

func (b *BitSet) Length() int

Length returns the 'logical size' of this BitSet. The 'logical size' is the highest set bit in the BitSet plus one. Returns zero if no bits are set.

func (*BitSet) Set

func (b *BitSet) Set(bit int)

Set sets the bit at the specified index to true.

func (*BitSet) SetBits

func (b *BitSet) SetBits() iter.Seq[int]

SetBits returns an iterator that iterates over the set bits of this BitSet

func (*BitSet) Size

func (b *BitSet) Size() int

Size returns the number of bits in this bit set.

func (*BitSet) String

func (b *BitSet) String() string

String returns a hexadecimal representation of the bits in this BitSet

func (*BitSet) ToBytes

func (b *BitSet) ToBytes() []byte

ToBytes returns a byte array containing all the set bits in this BitSet.

func (*BitSet) UnsetBits

func (b *BitSet) UnsetBits() iter.Seq[int]

UnsetBits returns an iterator that iterates over the unset bits of this BitSet

type Config

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

Config holds the values for configuring a BitSet.

type Option

type Option func(*Config)

Option configures a BitSet config

func NumBits

func NumBits(n int) Option

NumBits provides the option to set the number of bits used in a BitSet.

Jump to

Keyboard shortcuts

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