MCPcopy
hub / github.com/lionsoul2014/ip2region / IPCompare

Function IPCompare

maker/golang/xdb/util.go:48–61  ·  view source on GitHub ↗

IPCompare compares two IP addresses Returns: -1 if ip1 < ip2, 0 if ip1 == ip2, 1 if ip1 > ip2

(ip1, ip2 []byte)

Source from the content-addressed store, hash-verified

46// IPCompare compares two IP addresses
47// Returns: -1 if ip1 < ip2, 0 if ip1 == ip2, 1 if ip1 > ip2
48func IPCompare(ip1, ip2 []byte) int {
49 // for i := 0; i < len(ip1); i++ {
50 // if ip1[i] < ip2[i] {
51 // return -1
52 // }
53
54 // if ip1[i] > ip2[i] {
55 // return 1
56 // }
57 // }
58
59 // return 0
60 return bytes.Compare(ip1, ip2)
61}
62
63func IPAddOne(ip []byte) []byte {
64 var r = make([]byte, len(ip))

Callers 13

SegmentFromFunction · 0.70
RightBehindMethod · 0.70
AfterMethod · 0.70
ContainsMethod · 0.70
TestIPCompareFunction · 0.70
TestIPAddOneFunction · 0.70
TestIPSubOneFunction · 0.70
loadSegmentsMethod · 0.70
loadSegmentsMethod · 0.70
PutSegmentMethod · 0.70
IterateSegmentsFunction · 0.70
CheckSegmentsFunction · 0.70

Calls

no outgoing calls

Tested by 3

TestIPCompareFunction · 0.56
TestIPAddOneFunction · 0.56
TestIPSubOneFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…