mirror of https://github.com/k3s-io/k3s
Merge pull request #47515 from zhangxiaoyu-zidif/replace-scheduler-havesame
Automatic merge from submit-queue (batch tested with PRs 47043, 48448, 47515, 48446) Refactor slice intersection **What this PR does / why we need it**: In worst case, the original method is O(N^2), while current method is 3 * O(N). I think it is better. **Release note**: ```release-note NONE ```pull/6/head
commit
2f1ea7efcf
|
@ -879,11 +879,17 @@ func PodFitsHostPorts(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.No
|
|||
|
||||
// search two arrays and return true if they have at least one common element; return false otherwise
|
||||
func haveSame(a1, a2 []string) bool {
|
||||
for _, val1 := range a1 {
|
||||
for _, val2 := range a2 {
|
||||
if val1 == val2 {
|
||||
return true
|
||||
}
|
||||
m := map[string]int{}
|
||||
|
||||
for _, val := range a1 {
|
||||
m[val] = 1
|
||||
}
|
||||
for _, val := range a2 {
|
||||
m[val] = m[val] + 1
|
||||
}
|
||||
for _, val := range m {
|
||||
if val > 1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue