Categorygithub.com/m3db/bitset
modulepackage
2.0.0+incompatible
Repository: https://github.com/m3db/bitset.git
Documentation: pkg.go.dev

# README

bitset

Note: This is a fork of github.com/willf/bitset that provides a read only bitset that can be instantiated from a mmap'd bytes ref and also limits the scope of the API.

Go language library to map between non-negative integers and boolean values

Master Build Status Master Coverage Status Go Report Card GoDoc

Description

Package bitset implements bitsets, a mapping between non-negative integers and boolean values. It should be more efficient than map[uint] bool.

It provides methods for setting, clearing and testing individual integers.

BitSets are expanded to the size of the largest set bit; the memory allocation is approximately Max bits, where Max is the largest set bit. BitSets are never shrunk. On creation, a hint can be given for the number of bits that will be used.

Example use:

package main

import (
	"fmt"
	"math/rand"

	"github.com/m3db/bitset"
)

func main() {
	fmt.Printf("Hello from BitSet!\n")
	var b bitset.BitSet
	// play some Go Fish
	for i := 0; i < 100; i++ {
		card1 := uint(rand.Intn(52))
		card2 := uint(rand.Intn(52))
		b.Set(card1)
		if b.Test(card2) {
			fmt.Println("Go Fish!")
		}
		b.Clear(card1)
	}
}

As an alternative to BitSets, one should check out the 'big' package, which provides a (less set-theoretical) view of bitsets.

Godoc documentation is at: https://godoc.org/github.com/m3db/bitset

Installation

go get github.com/m3db/bitset

Running all tests

Before committing the code, please check if it passes all tests using (note: this will install some dependencies):

make qa

# Functions

NewBitSet returns a new bitset that can represent a set of n elements exactly.
NewReadOnlyBitSet returns a new read only bit set backed by a byte slice, this means it can be used with a mmap'd bytes ref.

# Structs

BitSet is a bitset set membership, it is safe for concurrent reads but not for concurrent read/writes.
ReadOnlyBitSet is a read only bitset set membership, it is safe for concurrent reads but not for concurrent read/writes.