https://github.com/patrickmn/go-bitset
Efficient map[uint32|64]bool-like bitset for Go
https://github.com/patrickmn/go-bitset
Last synced: 10 months ago
JSON representation
Efficient map[uint32|64]bool-like bitset for Go
- Host: GitHub
- URL: https://github.com/patrickmn/go-bitset
- Owner: patrickmn
- License: other
- Created: 2012-05-26T04:45:26.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2012-07-12T11:08:51.000Z (almost 14 years ago)
- Last Synced: 2025-04-04T04:32:09.072Z (about 1 year ago)
- Language: Go
- Homepage: https://patrickmn.com/projects/go-bitset/
- Size: 121 KB
- Stars: 14
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
go-bitset is an efficient implementation of a map between unsigned, 32-bit or
64-bit integers and boolean values. It provides methods for setting, clearing,
flipping, and testing individual integers.
go-bitset also provides set intersection, union, difference, complement, and
symmetric operations, as well as tests to check whether any, all, or no bits
are set, and the ability to query the bitset's length and number of set bits.
Bitsets are expanded automatically to the size of the largest bit set.
== Installation
go get github.com/pmylund/go-bitset
== Documentation
go doc github.com/pmylund/go-bitset
or http://go.pkgdoc.org/github.com/pmylund/go-bitset
== Usage
import "github.com/pmylund/go-bitset"
b := bitset.New32(10000)
b.Set(1000)
if b.Test(1000) {
fmt.Println("Bit 1000 is set!")
}
b.Clear(1000)
b.Set(10)
ob := bitset.New32(0)
// ob expands automatically
ob.Set(10)
if b.Intersection(ob).Count() > 1 {
fmt.Println("The two sets intersect!")
}
oob := bitset.New64(0)
oob.Set(1000000000)
go-bitset is based on bitset by Will Fitzgerald.