mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
Refactor slice intersection
This commit is contained in:
parent
5d2dbb58d7
commit
22e4abafae
@ -886,11 +886,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
|
// search two arrays and return true if they have at least one common element; return false otherwise
|
||||||
func haveSame(a1, a2 []string) bool {
|
func haveSame(a1, a2 []string) bool {
|
||||||
for _, val1 := range a1 {
|
m := map[string]int{}
|
||||||
for _, val2 := range a2 {
|
|
||||||
if val1 == val2 {
|
for _, val := range a1 {
|
||||||
return true
|
m[val] = 1
|
||||||
}
|
}
|
||||||
|
for _, val := range a2 {
|
||||||
|
m[val] = m[val] + 1
|
||||||
|
}
|
||||||
|
for _, val := range m {
|
||||||
|
if val > 1 {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user