bitset

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitset

type Bitset string

A Bitset is an immutable collection of bits. You can perform logical operations on it, but all mutable operations return a new Bitset. It is safe to compare directly using the comparison operator and to use as a map key.

func Build

func Build(bits ...int) Bitset

Build creates a new immutable Bitset where all the given bits are set

func Single

func Single(bit int) Bitset

Single returns a new Bitset where only the given bit is set. If the given bit is less than 32, Single does not allocate to create a new Bitset.

func (Bitset) And

func (bs Bitset) And(b2 Bitset) Bitset

And returns the logical AND of the two bitsets as a new Bitset

func (Bitset) AndNot

func (bs Bitset) AndNot(b2 Bitset) Bitset

AndNot returns the logical AND NOT of the two Bitsets as a new Bitset

func (Bitset) ForEach

func (bs Bitset) ForEach(yield func(int))

ForEach calls the given callback with the position of each bit set in this Bitset

func (Bitset) IsContainedBy

func (bs Bitset) IsContainedBy(b2 Bitset) bool

IsContainedBy returns whether this Bitset is contained by the given Bitset

func (Bitset) Or

func (bs Bitset) Or(b2 Bitset) Bitset

Or returns the logical OR of the two Bitsets as a new Bitset

func (Bitset) Overlaps

func (bs Bitset) Overlaps(b2 Bitset) bool

Overlaps returns whether this Bitset and the input have any bits in common

func (Bitset) Popcount

func (bs Bitset) Popcount() (count int)

Popcount returns the number of bits that are set in this Bitset

func (Bitset) Set

func (bs Bitset) Set(offset int) Bitset

Set returns a copy of this Bitset where the bit at `offset` is set

func (Bitset) SingleBit

func (bs Bitset) SingleBit() int

SingleBit returns the position of the single bit that is set in this Bitset If the Bitset is empty, or contains more than one set bit, it returns -1

Jump to

Keyboard shortcuts

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