Skip to content

Commit

Permalink
Simplify comparisons ​(X-Y) == 0 (#7495)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Oct 10, 2020
1 parent 43765b5 commit b5a913d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions shared/sliceutil/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func IntersectionUint64(s ...[]uint64) []uint64 {
for i, num := 1, len(s); i < num; i++ {
for _, k := range s[i] {
// Increment and check only if item is present in both, and no increment has happened yet.
if _, found := m[k]; found && (i-m[k]) == 0 {
if _, found := m[k]; found && i == m[k] {
m[k]++
if m[k] == num {
intersect = append(intersect, k)
Expand Down Expand Up @@ -163,7 +163,7 @@ func IntersectionInt64(s ...[]int64) []int64 {
}
for i, num := 1, len(s); i < num; i++ {
for _, k := range s[i] {
if _, found := m[k]; found && (i-m[k]) == 0 {
if _, found := m[k]; found && i == m[k] {
m[k]++
if m[k] == num {
intersect = append(intersect, k)
Expand Down Expand Up @@ -269,7 +269,7 @@ func IntersectionByteSlices(s ...[][]byte) [][]byte {
}
for i, num := 1, len(s); i < num; i++ {
for _, k := range s[i] {
if _, found := m[string(k)]; found && (i-m[string(k)]) == 0 {
if _, found := m[string(k)]; found && i == m[string(k)] {
m[string(k)]++
if m[string(k)] == num {
inter = append(inter, k)
Expand Down

0 comments on commit b5a913d

Please sign in to comment.