bitset

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package bitset implements bitsets, a mapping between non-negative integers and boolean values.

Studied github.com/bits-and-blooms/bitset inside out and rewrote needed parts from scratch for this project.

This implementation is heavily optimized for this internal use case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet256

type BitSet256 [4]uint64

BitSet256 represents a fixed size bitset from [0..255]

func (*BitSet256) All

func (b *BitSet256) All() []uint8

All returns all set bits. This has a simpler API but is slower than AsSlice.

func (*BitSet256) AsSlice

func (b *BitSet256) AsSlice(buf *[256]uint8) []uint8

AsSlice returns all set bits as slice of uint8 without heap allocations.

func (*BitSet256) Clear

func (b *BitSet256) Clear(bit uint8)

Clear clears the bit.

func (*BitSet256) FirstSet

func (b *BitSet256) FirstSet() (first uint8, ok bool)

FirstSet returns the first bit set along with an ok code.

func (*BitSet256) Intersection

func (b *BitSet256) Intersection(c *BitSet256) (bs BitSet256)

Intersection computes the intersection of base set with the compare set. This is the BitSet equivalent of & (and).

func (*BitSet256) IntersectionCardinality

func (b *BitSet256) IntersectionCardinality(c *BitSet256) (cnt int)

IntersectionCardinality computes the popcount of the intersection.

func (*BitSet256) IntersectionTop

func (b *BitSet256) IntersectionTop(c *BitSet256) (top uint8, ok bool)

IntersectionTop computes the intersection of base set with the compare set. If the result set isn't empty, it returns the top most set bit and true.

func (*BitSet256) IntersectsAny

func (b *BitSet256) IntersectsAny(c *BitSet256) bool

IntersectsAny returns true if the intersection of base set with the compare set is not the empty set.

func (*BitSet256) IsEmpty

func (b *BitSet256) IsEmpty() bool

IsEmpty returns true if no bit is set.

func (*BitSet256) NextSet

func (b *BitSet256) NextSet(bit uint8) (next uint8, iok bool)

NextSet returns the next bit set from the specified start bit, including possibly the current bit along with an ok code.

func (*BitSet256) Rank

func (b *BitSet256) Rank(idx uint8) (rnk int)

Rank returns the set bits up to and including to idx.

func (*BitSet256) Set

func (b *BitSet256) Set(bit uint8)

Set sets the bit.

func (*BitSet256) Size

func (b *BitSet256) Size() int

Size is the number of set bits (popcount).

func (*BitSet256) String

func (b *BitSet256) String() string

String implements fmt.Stringer.

func (*BitSet256) Test

func (b *BitSet256) Test(bit uint8) (ok bool)

Test if the bit is set.

func (*BitSet256) Union

func (b *BitSet256) Union(c *BitSet256) (bs BitSet256)

Union creates the union of base set with compare set. This is the BitSet equivalent of | (or).

Jump to

Keyboard shortcuts

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