-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f087e8
commit aa0008c
Showing
44 changed files
with
10,273 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package bls | ||
|
||
// BitIterator is an iterator through bits. | ||
type BitIterator struct { | ||
arr []uint64 | ||
n uint | ||
} | ||
|
||
// NewBitIterator creates a new bit iterator given an array of ints. | ||
func NewBitIterator(arr []uint64) BitIterator { | ||
return BitIterator{arr, uint(len(arr) * 64)} | ||
} | ||
|
||
// Next returns the next bit in the bit iterator with the | ||
// second return value as true when finished. | ||
func (bi *BitIterator) Next() (bool, bool) { | ||
if bi.n == 0 { | ||
return false, true | ||
} | ||
bi.n-- | ||
part := bi.n / 64 | ||
bit := bi.n - (part * 64) | ||
return bi.arr[part]&(1<<bit) > 0, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package bls_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/phoreproject/bls" | ||
) | ||
|
||
func TestBitIterator(t *testing.T) { | ||
a := bls.NewBitIterator([]uint64{0xa953d79b83f6ab59, 0x6dea2059e200bd39}) | ||
expected := "01101101111010100010000001011001111000100000000010111101001110011010100101010011110101111001101110000011111101101010101101011001" | ||
|
||
for _, e := range expected { | ||
bit, done := a.Next() | ||
if done { | ||
t.Fatal("iterator finished too soon") | ||
} | ||
if bit != (e == '1') { | ||
t.Fatal("invalid bit") | ||
} | ||
} | ||
|
||
if _, done := a.Next(); done != true { | ||
t.Fatal("iterator did not finish in time") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package bls_test |
Oops, something went wrong.