1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
// Code generated by automation. DO NOT EDIT
package generics_tree
import (
"math/bits"
"github.com/kentik/patricia"
)
const _leftmost64Bit = uint64(1 << 63)
type treeNodeV6[T any] struct {
Left uint // left node index: 0 for not set
Right uint // right node index: 0 for not set
prefixLeft uint64
prefixRight uint64
prefixLength uint
TagCount int
}
func (n *treeNodeV6[T]) MatchCount(address patricia.IPv6Address) uint {
length := address.Length
if length > n.prefixLength {
length = n.prefixLength
}
matches := uint(bits.LeadingZeros64(n.prefixLeft ^ address.Left))
if matches == 64 && length > 64 {
matches += uint(bits.LeadingZeros64(n.prefixRight ^ address.Right))
}
if matches > length {
return length
}
return matches
}
// ShiftPrefix shifts the prefix by the input shiftCount
func (n *treeNodeV6[T]) ShiftPrefix(shiftCount uint) {
n.prefixLeft, n.prefixRight, n.prefixLength = patricia.ShiftLeftIPv6(n.prefixLeft, n.prefixRight, n.prefixLength, shiftCount)
}
// IsLeftBitSet returns whether the leftmost bit is set
func (n *treeNodeV6[T]) IsLeftBitSet() bool {
return n.prefixLeft >= _leftmost64Bit
}
// MergeFromNodes updates the prefix and prefix length from the two input nodes
func (n *treeNodeV6[T]) MergeFromNodes(left *treeNodeV6[T], right *treeNodeV6[T]) {
n.prefixLeft, n.prefixRight, n.prefixLength = patricia.MergePrefixes64(left.prefixLeft, left.prefixRight, left.prefixLength, right.prefixLeft, right.prefixRight, right.prefixLength)
}
|