BitSet data structure in golang
Go
Latest commit d09b64c Feb 12, 2017 @xojoc s
Permalink
Failed to load latest commit information.
README.md s Feb 12, 2017
bench_test.go s Nov 23, 2016
bitset.go s Nov 23, 2016
bitset_test.go s Nov 23, 2016
examples_test.go s Nov 23, 2016
property_test.go s Nov 23, 2016

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.