-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Refactor podListEqual() #48473
Refactor podListEqual() #48473
Conversation
Hi @zhangxiaoyu-zidif. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/cc @wojtek-t |
m[val] = m[val] + 1 | ||
} | ||
|
||
return len(list1) == len(m) |
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.
This isn't correct. It will return true e.g for [a, b] and [a, a]
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.
yes, I forget to check m[xxx] == 2. Thanks.
@wojtek-t Hi, I fix it, PTAL. Thanks a lot. |
/ok-to-test |
return false | ||
} | ||
} | ||
|
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.
No needed line?
/test pull-kubernetes-unit |
} | ||
|
||
for _, v := range m { | ||
if v != 2 { |
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.
This still changes the semantic compared to the previous version.
In particular what if you have:
[a, a, b] and [a, a, b]
Those are obviously the same, but your function will return false.
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.
Yes, I need more time to deal with it. Thanks a lot. =)
@wojtek-t Sorry to trouble you again. =) |
if !contains { | ||
|
||
m1 := map[*v1.Pod]int{} | ||
m2 := map[*v1.Pod]int{} |
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 would like to avoid allocating two maps.
How about this pattern:
for list1 {
m[val] = m[val] + 1
}
for list2 {
m[val] = m[val] - 1
}
for m {
if m[val] != 0 {
return false
}
}
?
@wojtek-t you are right. Your method is much dainty. Thanks a lot. |
@resouer I delete that empty line. Thanks =) |
if !contains { | ||
|
||
m := map[*v1.Pod]int{} | ||
|
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.
nit: remove this empty line
for _, val := range list1 { | ||
m[val] = m[val] + 1 | ||
} | ||
|
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.
nit: remove this empty line
for _, val := range list2 { | ||
m[val] = m[val] - 1 | ||
} | ||
|
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.
nit: remove this empty line
@wojtek-t PTAL =) |
/lgtm |
/approve no-issue |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wojtek-t, zhangxiaoyu-zidif Associated issue requirement bypassed by: wojtek-t The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/test pull-kubernetes-federation-e2e-gce |
Automatic merge from submit-queue (batch tested with PRs 48473, 48341) |
What this PR does / why we need it:
To solve the problem:
this is not correct if there are duplicate pods in the list.
for example: podListEqual([a, a, b], [a, b, b]) will return true
Special notes for your reviewer:
the original method is O(N^2), while current method is 3* O(N).
I think it is much better.
Release note: