Skip to content

Commit

Permalink
Update zero-length detection
Browse files Browse the repository at this point in the history
  • Loading branch information
b97tsk committed Jan 31, 2024
1 parent 7b44fa7 commit 0e2802f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
10 changes: 5 additions & 5 deletions difference.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func Difference[E Elem[E]](z, x, y Set[E]) Set[E] {
inv := false

for {
if len(x) == 0 {
x, y = y, x
inv = !inv
}
if len(x) == 0 || len(y) == 0 {
if len(x) == 0 {
x, y = y, x
inv = !inv
}

if len(y) == 0 {
if !inv {
z = append(z, x...)
}
Expand Down
6 changes: 1 addition & 5 deletions intersection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ func Intersection[E Elem[E]](z, x, y Set[E]) Set[E] {
z = z[:0]

for {
if len(x) == 0 {
x, y = y, x
}

if len(y) == 0 {
if len(x) == 0 || len(y) == 0 {
return z
}

Expand Down
10 changes: 5 additions & 5 deletions issubsetof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ func (x Set[E]) IsSubsetOf(y Set[E]) bool {
inv := false

for {
if len(x) == 0 {
x, y = y, x
inv = !inv
}
if len(x) == 0 || len(y) == 0 {
if len(x) == 0 {
x, y = y, x
inv = !inv
}

if len(y) == 0 {
return inv || len(x) == 0
}

Expand Down
6 changes: 1 addition & 5 deletions overlap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import "sort"
// Overlaps reports whether the intersection of x and y is not empty.
func (x Set[E]) Overlaps(y Set[E]) bool {
for {
if len(x) == 0 {
x, y = y, x
}

if len(y) == 0 {
if len(x) == 0 || len(y) == 0 {
return false
}

Expand Down
11 changes: 5 additions & 6 deletions symdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ func SymmetricDifference[E Elem[E]](z, x, y Set[E]) Set[E] {
z = z[:0]

for {
if len(x) == 0 {
x, y = y, x
}
if len(x) == 0 || len(y) == 0 {
if len(x) == 0 {
x, y = y, x
}

if len(y) == 0 {
z = appendIntervals(z, x...)
return z
return appendIntervals(z, x...)
}

if x[0].High.Compare(y[0].High) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions union.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ func Union[E Elem[E]](z, x, y Set[E]) Set[E] {
z = z[:0]

for {
if len(x) == 0 {
x, y = y, x
}
if len(x) == 0 || len(y) == 0 {
if len(x) == 0 {
x, y = y, x
}

if len(y) == 0 {
return append(z, x...)
}

Expand Down

0 comments on commit 0e2802f

Please sign in to comment.