BitSet data structure in golang
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
bench_test.go
bitset.go
bitset_test.go
examples_test.go
property_test.go

README.md

BitSet data structure

bitset is a library written in golang implementing a BitSet data structure.

Usage

First install the library with

go get xojoc.pw/bitset

...then run...

go test

if something fails open an issue.

As an example let's list all the composite numbers below 10:

package main

import (
	"fmt"
	"xojoc.pw/bitset"
)

func main() {
        c := &bitset.BitSet{}
        // Set all prime numbers to true.
        c.Set(2)
        c.Set(3)
        c.Set(5)
        c.Set(7)
        c.ToggleRange(1,10+1)
        for i := 1; i < c.Len(); i++ {
                if c.Get(i) {
                        fmt.Printf("%d is composite\n", i)
                }
        }
}

Output:

1 is composite
4 is composite
6 is composite
8 is composite
9 is composite
10 is composite

see godoc for the complete documentation.

Why?

Also see why use xojoc.pw/bitset and not math/big.

Who?

bitset was written by Alexandru Cojocaru (https://xojoc.pw).

Donate!

License

bitset is Free Software and in the Public Domain. No warranty.