Skip to content

Commit

Permalink
Merge pull request #248 from toli-belo/fix_difference_empty_set2
Browse files Browse the repository at this point in the history
Fix difference panic on empty set2
  • Loading branch information
lemire authored Mar 28, 2020
2 parents 4d53b29 + efdda79 commit 4318595
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions setutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func equal(a, b []uint16) bool {

func difference(set1 []uint16, set2 []uint16, buffer []uint16) int {
if 0 == len(set2) {
buffer = buffer[:len(set1)]
for k := 0; k < len(set1); k++ {
buffer[k] = set1[k]
}
Expand Down
17 changes: 17 additions & 0 deletions setutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ func TestSetUtilDifference(t *testing.T) {
result = result[:nl]

assert.Equal(t, expectedresult, result)

// empty set2
data2 = []uint16{}
expectedresult = []uint16{0, 1, 2, 3, 4, 9}
nl = difference(data1, data2, result)
result = result[:nl]

assert.Equal(t, expectedresult, result)

// empty set 1
data1 = []uint16{}
data2 = []uint16{2, 3, 4, 5, 8, 9, 11}
expectedresult = []uint16{}
nl = difference(data1, data2, result)
result = result[:nl]

assert.Equal(t, expectedresult, result)
}

func TestSetUtilUnion(t *testing.T) {
Expand Down

0 comments on commit 4318595

Please sign in to comment.