func TestCompare(t *testing.T) { for i, tt := range compareTests { if n := ipaddr.Compare(&tt.in[0], &tt.in[1]); n != tt.n { t.Errorf("#%d: got %v for %v; want %v", i, n, tt.in, tt.n) } } }
func BenchmarkCompareIPv6(b *testing.B) { p1 := toPrefix("2001:db8:f001:f002::/64") p2 := toPrefix("2001:db8:f001:f003::/64") for i := 0; i < b.N; i++ { ipaddr.Compare(p1, p2) } }
func BenchmarkCompareIPv4(b *testing.B) { p1 := toPrefix("192.168.1.0/24") p2 := toPrefix("192.168.2.0/24") for i := 0; i < b.N; i++ { ipaddr.Compare(p1, p2) } }
func (ps byAddrLen) Less(i, j int) bool { n := ipaddr.Compare(&ps[i], &ps[j]) if n < 0 { return true } if n > 0 { return false } li, lj := ps[i].Len(), ps[j].Len() if li < lj { return true } if li > lj { return false } return false }
func BenchmarkCompareIPv6(b *testing.B) { for i := 0; i < b.N; i++ { ipaddr.Compare(ipv6Pair[0], ipv6Pair[1]) } }
func (h *prefixHeap) Less(i, j int) bool { return ipaddr.Compare(&(*h)[i], &(*h)[j]) < 0 }