Skip to content
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

Merged
merged 1 commit into from
Jul 5, 2017
Merged

Refactor podListEqual() #48473

merged 1 commit into from
Jul 5, 2017

Conversation

zhangxiaoyu-zidif
Copy link
Contributor

@zhangxiaoyu-zidif zhangxiaoyu-zidif commented Jul 4, 2017

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:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 4, 2017
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 4, 2017
@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jul 4, 2017
@zhangxiaoyu-zidif
Copy link
Contributor Author

/cc @wojtek-t

m[val] = m[val] + 1
}

return len(list1) == len(m)
Copy link
Member

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]

Copy link
Contributor Author

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.

@zhangxiaoyu-zidif
Copy link
Contributor Author

zhangxiaoyu-zidif commented Jul 4, 2017

@wojtek-t Hi, I fix it, PTAL. Thanks a lot.

@resouer
Copy link
Contributor

resouer commented Jul 4, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 4, 2017
return false
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needed line?

@zhangxiaoyu-zidif
Copy link
Contributor Author

/test pull-kubernetes-unit

}

for _, v := range m {
if v != 2 {
Copy link
Member

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.

Copy link
Contributor Author

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. =)

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 5, 2017
@zhangxiaoyu-zidif
Copy link
Contributor Author

@wojtek-t Sorry to trouble you again. =)
PTAL.

if !contains {

m1 := map[*v1.Pod]int{}
m2 := map[*v1.Pod]int{}
Copy link
Member

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
  }
}

?

@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 5, 2017
@zhangxiaoyu-zidif
Copy link
Contributor Author

@wojtek-t you are right. Your method is much dainty. Thanks a lot.

@zhangxiaoyu-zidif
Copy link
Contributor Author

@resouer I delete that empty line. Thanks =)

if !contains {

m := map[*v1.Pod]int{}

Copy link
Member

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
}

Copy link
Member

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
}

Copy link
Member

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

@zhangxiaoyu-zidif
Copy link
Contributor Author

@wojtek-t PTAL =)

@wojtek-t
Copy link
Member

wojtek-t commented Jul 5, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 5, 2017
@wojtek-t
Copy link
Member

wojtek-t commented Jul 5, 2017

/approve no-issue

@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 5, 2017
@zhangxiaoyu-zidif
Copy link
Contributor Author

/test pull-kubernetes-federation-e2e-gce

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 48473, 48341)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants