Skip to content

Commit

Permalink
Merge pull request #7 from yourbasic/tip
Browse files Browse the repository at this point in the history
Tip
  • Loading branch information
korthaj authored Jun 20, 2017
2 parents 8fa2857 + 32a092b commit 076b22d
Show file tree
Hide file tree
Showing 5 changed files with 601 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Your basic bit
# Your basic bit [![GoDoc](https://godoc.org/github.com/yourbasic/bit?status.svg)][godoc-bit]

### Golang set data structure with bonus bit-twiddling functions

Expand Down
18 changes: 0 additions & 18 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ package bit

import "testing"

func BenchmarkLeadingZeros(b *testing.B) {
for i := 0; i < b.N; i++ {
LeadingZeros(0xcafecafecafecafe)
}
}

func BenchmarkTrailingZeros(b *testing.B) {
for i := 0; i < b.N; i++ {
TrailingZeros(0xcafecafecafecafe)
}
}

func BenchmarkCount(b *testing.B) {
for i := 0; i < b.N; i++ {
Count(0xcafecafecafecafe)
}
}

// Number of words in test set.
const nw = 1 << 10

Expand Down
6 changes: 6 additions & 0 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (

// LeadingZeros returns the number of leading zero bits in w;
// it returns 64 when w is zero.
//
// Deprecated: In Go 1.9 this function is available in package math/bits as LeadingZeros64.
func LeadingZeros(w uint64) int {
// Fill word with ones on the right, e.g. 0x0000f308 -> 0x0000ffff.
w |= w >> 1
Expand All @@ -27,6 +29,8 @@ func LeadingZeros(w uint64) int {

// TrailingZeros returns the number of trailing zero bits in w;
// it returns 64 when w is zero.
//
// Deprecated: In Go 1.9 this function is available in package math/bits as TrailingZeros64.
func TrailingZeros(w uint64) int {
// “Using de Bruijn Sequences to Index a 1 in a Computer Word”,
// Leiserson, Prokop, and Randall, MIT, 1998.
Expand All @@ -53,6 +57,8 @@ func init() {
}

// Count returns the number of nonzero bits in w.
//
// Deprecated: In Go 1.9 this function is available in package math/bits as OnesCount64.
func Count(w uint64) int {
// “Software Optimization Guide for AMD64 Processors”, Section 8.6.
const maxw = 1<<64 - 1
Expand Down
2 changes: 2 additions & 0 deletions set.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !go1.9

// Package bit provides a bit array implementation
// and some utility bit functions.
//
Expand Down
Loading

0 comments on commit 076b22d

Please sign in to comment.