MCPcopy Create free account
hub / github.com/encodeous/nylon / commonBits

Function commonBits

polyamide/device/allowedips.go:35–56  ·  view source on GitHub ↗
(ip1, ip2 []byte)

Source from the content-addressed store, hash-verified

33}
34
35func commonBits(ip1, ip2 []byte) uint8 {
36 size := len(ip1)
37 if size == net.IPv4len {
38 a := binary.BigEndian.Uint32(ip1)
39 b := binary.BigEndian.Uint32(ip2)
40 x := a ^ b
41 return uint8(bits.LeadingZeros32(x))
42 } else if size == net.IPv6len {
43 a := binary.BigEndian.Uint64(ip1)
44 b := binary.BigEndian.Uint64(ip2)
45 x := a ^ b
46 if x != 0 {
47 return uint8(bits.LeadingZeros64(x))
48 }
49 a = binary.BigEndian.Uint64(ip1[8:])
50 b = binary.BigEndian.Uint64(ip2[8:])
51 x = a ^ b
52 return 64 + uint8(bits.LeadingZeros64(x))
53 } else {
54 panic("Wrong size bit string")
55 }
56}
57
58func (node *trieEntry) addToPeerEntries() {
59 node.perPeerElem = node.peer.trieEntries.PushBack(node)

Callers 6

InsertMethod · 0.85
LookupMethod · 0.85
nodePlacementMethod · 0.85
insertMethod · 0.85
lookupMethod · 0.85
TestCommonBitsFunction · 0.85

Calls

no outgoing calls

Tested by 3

InsertMethod · 0.68
LookupMethod · 0.68
TestCommonBitsFunction · 0.68