MCPcopy
hub / github.com/fluid-cloudnative/fluid / SortIpAddresses

Function SortIpAddresses

pkg/utils/net.go:25–46  ·  view source on GitHub ↗
(ips []string)

Source from the content-addressed store, hash-verified

23)
24
25func SortIpAddresses(ips []string) (orderedIps []string) {
26 realIPs := make([]net.IP, 0, len(ips))
27 keys := make(map[string]bool)
28
29 for _, ip := range ips {
30 // Avoid duplicated keys
31 if _, value := keys[ip]; !value {
32 keys[ip] = true
33 realIPs = append(realIPs, net.ParseIP(ip))
34 }
35 }
36
37 sort.Slice(realIPs, func(i, j int) bool {
38 return bytes.Compare(realIPs[i], realIPs[j]) < 0
39 })
40
41 for _, ip := range realIPs {
42 orderedIps = append(orderedIps, ip.String())
43 }
44
45 return
46}

Callers 1

GetIpAddressesOfNodesFunction · 0.92

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected