Skip to content

Commit

Permalink
chenge bls library
Browse files Browse the repository at this point in the history
  • Loading branch information
boohyunsik committed Jul 10, 2019
1 parent 4f087e8 commit aa0008c
Show file tree
Hide file tree
Showing 44 changed files with 10,273 additions and 10 deletions.
24 changes: 24 additions & 0 deletions bls/bititerator.go
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
}
26 changes: 26 additions & 0 deletions bls/bititerator_test.go
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")
}
}
1 change: 1 addition & 0 deletions bls/curve_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package bls_test
Loading

0 comments on commit aa0008c

Please sign in to comment.