Skip to content

Commit

Permalink
add SetBitsetFrom() to resolve #85
Browse files Browse the repository at this point in the history
  • Loading branch information
SignorMercurio committed Apr 21, 2022
1 parent 117140e commit 02db5c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (b *BitSet) safeSet() []uint64 {
return b.set
}

// SetBitsetFrom fills the bitset with an array of integers without creating a new BitSet instance
func (b *BitSet) SetBitsetFrom(buf []uint64) {
b.length = uint(len(buf)) * 64
b.set = buf
}

// From is a constructor used to create a BitSet from an array of integers
func From(buf []uint64) *BitSet {
return FromWithLength(uint(len(buf))*64, buf)
Expand Down
12 changes: 12 additions & 0 deletions bitset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,18 @@ func TestSafeSet(t *testing.T) {
}
}

func TestSetBitsetFrom(t *testing.T) {
u := []uint64{2, 3, 5, 7, 11}
b := new(BitSet)
b.SetBitsetFrom(u)
outType := fmt.Sprintf("%T", b)
expType := "*bitset.BitSet"
if outType != expType {
t.Error("Expecting type: ", expType, ", gotf:", outType)
return
}
}

func TestFrom(t *testing.T) {
u := []uint64{2, 3, 5, 7, 11}
b := From(u)
Expand Down

0 comments on commit 02db5c7

Please sign in to comment.