bitset

package
v0.0.0-...-ac611bd Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 1 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 smaller and faster as the more general github.com/bits-and-blooms/bitset.

All functions can be inlined!

can inline BitSet.Set with cost 63
can inline BitSet.Clear with cost 24
can inline BitSet.Test with cost 26
can inline BitSet.Rank0 with cost 57
can inline BitSet.Clone with cost 7
can inline BitSet.Compact with cost 35
can inline BitSet.FirstSet with cost 25
can inline BitSet.NextSet with cost 71
can inline BitSet.AsSlice with cost 50
can inline BitSet.All with cost 70
can inline BitSet.IntersectsAny with cost 42
can inline BitSet.IntersectionTop with cost 56
can inline BitSet.IntersectionCardinality with cost 35
can inline (*BitSet).InPlaceIntersection with cost 71
can inline (*BitSet).InPlaceUnion with cost 77
can inline BitSet.Size with cost 16
can inline popcount with cost 12
can inline popcountAnd with cost 30

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet

type BitSet []uint64

A BitSet is a slice of words. This is an internal package with a wide open public API.

func (BitSet) All

func (b BitSet) All() []uint

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

func (BitSet) AsSlice

func (b BitSet) AsSlice(buf []uint) []uint

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

This is faster than All, but also more dangerous, it panics if the capacity of buf is < b.Size()

func (BitSet) Clear

func (b BitSet) Clear(i uint) BitSet

Clear bit i to 0.

func (BitSet) Clone

func (b BitSet) Clone() BitSet

Clone this BitSet, returning a new BitSet that has the same bits set.

func (BitSet) Compact

func (b BitSet) Compact() BitSet

Compact, preserve all set bits, while minimizing memory usage.

func (BitSet) FirstSet

func (b BitSet) FirstSet() (uint, bool)

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

func (*BitSet) InPlaceIntersection

func (b *BitSet) InPlaceIntersection(c BitSet)

InPlaceIntersection overwrites and computes the intersection of base set with the compare set. This is the BitSet equivalent of & (and). If len(c) > len(b), new memory is allocated.

func (*BitSet) InPlaceUnion

func (b *BitSet) InPlaceUnion(c BitSet)

InPlaceUnion creates the destructive union of base set with compare set. This is the BitSet equivalent of | (or). If len(c) > len(b), new memory is allocated.

func (BitSet) IntersectionCardinality

func (b BitSet) IntersectionCardinality(c BitSet) int

IntersectionCardinality computes the popcount of the intersection.

func (BitSet) IntersectionTop

func (b BitSet) IntersectionTop(c BitSet) (top uint, 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 (BitSet) IntersectsAny

func (b BitSet) IntersectsAny(c BitSet) bool

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

func (BitSet) NextSet

func (b BitSet) NextSet(i uint) (uint, bool)

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

func (BitSet) Rank0

func (b BitSet) Rank0(i uint) (rnk int)

Rank0 is equal to Rank(i) - 1

With inlined popcount to make Rank0 itself inlineable.

func (BitSet) Set

func (b BitSet) Set(i uint) BitSet

Set bit i to 1, the capacity of the bitset is increased accordingly.

func (BitSet) Size

func (b BitSet) Size() int

Size (number of set bits).

func (BitSet) Test

func (b BitSet) Test(i uint) (ok bool)

Test if bit i is set.

Jump to

Keyboard shortcuts

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