-
Notifications
You must be signed in to change notification settings - Fork 950
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
bugfix: StringSliceEqual should also consider duplicate items in slice #2561
bugfix: StringSliceEqual should also consider duplicate items in slice #2561
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2561 +/- ##
==========================================
+ Coverage 69.07% 69.14% +0.06%
==========================================
Files 278 278
Lines 18564 18565 +1
==========================================
+ Hits 12823 12836 +13
+ Misses 4273 4259 -14
- Partials 1468 1470 +2
|
1da79a5
to
37461f8
Compare
pkg/utils/utils.go
Outdated
@@ -306,6 +306,7 @@ func IsFileExist(file string) bool { | |||
} | |||
|
|||
// StringSliceEqual compare two string slice, ignore the order. | |||
// we also should consider if there has duplicate items in slice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see here you are describing the case. But for fixing a bug, we should describe the functionality it provides. Maybe you can update the comment about when this function returns true precisely. @HusterWan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
|
||
// second list all items in s2 | ||
for _, v := range s2 { | ||
mapKeys[v]-- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
embedded check here for more efficient
mapKeys[v]--
if mapKeys[v] < 0 {
return false
}
This check covers two situations
- if the key is not exists, mapKey[v] == -1
- if the key is redundant, mapKey[v] < 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good advice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are so talented. @zhuangqh 👍 🦁 🐸 🐼
9bc7972
to
b08a818
Compare
Signed-off-by: ziren.wzr <ziren.wzr@alibaba-inc.com>
b08a818
to
fd23316
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool👍 LGTM
Signed-off-by: ziren.wzr ziren.wzr@alibaba-inc.com
Ⅰ. Describe what this PR did
When a slice have duplicate items, the
StringSliceEqual
may get wrong answerⅡ. Does this pull request fix one issue?
fixes: #2560
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews