Skip to content

m3db/bitset

 
 

Repository files navigation

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

About

Go package implementing bitsets

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 63.0%
  • Makefile 37.0%