Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SetBitsetFrom() to resolve #85 #104

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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