Skip to content

Commit

Permalink
Merge pull request #168 from skullhole/167.1
Browse files Browse the repository at this point in the history
len64() - fix docstring, tests for go1.8
  • Loading branch information
lemire authored Aug 24, 2024
2 parents 467471f + 064e45b commit 08d15d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions leading_zeros_18.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var len8tab = "" +
"\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08" +
"\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08"

// Len64 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
// len64 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
func len64(x uint64) (n uint) {
if x >= 1<<32 {
x >>= 32
Expand All @@ -39,5 +39,5 @@ func len64(x uint64) (n uint) {
}

func leadingZeroes64(v uint64) uint {
return 64 - len64(x)
return 64 - len64(v)
}
18 changes: 18 additions & 0 deletions leading_zeros_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !go1.9
// +build !go1.9

package bitset

import (
"testing"
)

func TestLen64(t *testing.T) {
for i := 0; i < 64; i++ {
received := len64(uint64(1) << i)
expected := uint(i + 1)
if received != expected {
t.Errorf("len64(%b) is incorrect: received %d, expected %d", uint64(1)<<i, received, expected)
}
}
}

0 comments on commit 08d15d2

Please sign in to comment.