Skip to content

Commit

Permalink
bitset: rename BitSet to Bitset
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilgarg28 committed Aug 1, 2015
1 parent e9eba76 commit 26ae6e0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bitset
const word = uint64(64)
const logword = uint(6)

type BitSet struct {
type Bitset struct {
length uint64
bits []uint64
}
Expand All @@ -12,9 +12,9 @@ func getSize(length uint64) uint64 {
return uint64((length + word - 1) / word)
}

func New(length uint64) *BitSet {
func New(length uint64) *Bitset {
size := getSize(length)
return &BitSet{
return &Bitset{
length,
make([]uint64, size),
}
Expand All @@ -26,31 +26,31 @@ func getIndex(pos uint64) (q uint64, r uint) {
return
}

func (b *BitSet) Length() uint64 {
func (b *Bitset) Length() uint64 {
return b.length
}

func (b *BitSet) Get(pos uint64) bool {
func (b *Bitset) Get(pos uint64) bool {
q, r := getIndex(pos)
bit := (b.bits[q] >> r) & 1
return bit != 0
}

func (b *BitSet) Set(pos uint64) bool {
func (b *Bitset) Set(pos uint64) bool {
current := b.Get(pos)
q, r := getIndex(pos)
b.bits[q] |= (1 << r)
return current
}

func (b *BitSet) Clear(pos uint64) bool {
func (b *Bitset) Clear(pos uint64) bool {
current := b.Get(pos)
q, r := getIndex(pos)
b.bits[q] &= ^(1 << r)
return current
}

func (b *BitSet) Flip(pos uint64) bool {
func (b *Bitset) Flip(pos uint64) bool {
current := b.Get(pos)
q, r := getIndex(pos)
b.bits[q] ^= (1 << r)
Expand Down

0 comments on commit 26ae6e0

Please sign in to comment.