diff --git a/bool_tree/tree_v4.go b/bool_tree/tree_v4.go index f1683ea..9f99c25 100644 --- a/bool_tree/tree_v4.go +++ b/bool_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, bool) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []bool) { ret := make([]bool, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []bool) { + ret := make([]bool, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []bool, address patricia.IPv4Address) (bool, []bool) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []bool, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []bool) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []bool, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []bool, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []bool, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/bool_tree/tree_v6_generated.go b/bool_tree/tree_v6_generated.go index fc865b3..1cc574b 100644 --- a/bool_tree/tree_v6_generated.go +++ b/bool_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, bool) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []bool) { ret := make([]bool, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []bool) { + ret := make([]bool, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []bool, address patricia.IPv6Address) (bool, []bool) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []bool, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []bool) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []bool, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []bool, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []bool, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/byte_tree/tree_v4.go b/byte_tree/tree_v4.go index 9218660..90da674 100644 --- a/byte_tree/tree_v4.go +++ b/byte_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, byte) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []byte) { ret := make([]byte, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []byte) { + ret := make([]byte, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []byte, address patricia.IPv4Address) (bool, []byte) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []byte, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []byte) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []byte, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []byte, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []byte, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/byte_tree/tree_v6_generated.go b/byte_tree/tree_v6_generated.go index cbbc9ac..f68ca57 100644 --- a/byte_tree/tree_v6_generated.go +++ b/byte_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, byte) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []byte) { ret := make([]byte, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []byte) { + ret := make([]byte, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []byte, address patricia.IPv6Address) (bool, []byte) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []byte, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []byte) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []byte, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []byte, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []byte, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/complex128_tree/tree_v4.go b/complex128_tree/tree_v4.go index 932e6a0..aad755a 100644 --- a/complex128_tree/tree_v4.go +++ b/complex128_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, complex128) // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []complex128) { ret := make([]complex128, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []complex128) { + ret := make([]complex128, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []complex128, address patricia.IPv4Address) (bool, []complex128) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []complex128, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []complex128) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []complex128, address patricia.IPv4Ad if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []complex128, address patricia.IPv4Ad // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []complex128, address patricia.IPv4Ad if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/complex128_tree/tree_v6_generated.go b/complex128_tree/tree_v6_generated.go index fac7fae..7133497 100644 --- a/complex128_tree/tree_v6_generated.go +++ b/complex128_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, complex128) // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []complex128) { ret := make([]complex128, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []complex128) { + ret := make([]complex128, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []complex128, address patricia.IPv6Address) (bool, []complex128) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []complex128, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []complex128) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []complex128, address patricia.IPv6Ad if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []complex128, address patricia.IPv6Ad // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []complex128, address patricia.IPv6Ad if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/complex64_tree/tree_v4.go b/complex64_tree/tree_v4.go index 4a7c460..08490c6 100644 --- a/complex64_tree/tree_v4.go +++ b/complex64_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, complex64) // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []complex64) { ret := make([]complex64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []complex64) { + ret := make([]complex64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []complex64, address patricia.IPv4Address) (bool, []complex64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []complex64, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []complex64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []complex64, address patricia.IPv4Add if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []complex64, address patricia.IPv4Add // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []complex64, address patricia.IPv4Add if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/complex64_tree/tree_v6_generated.go b/complex64_tree/tree_v6_generated.go index c8f1531..e53b941 100644 --- a/complex64_tree/tree_v6_generated.go +++ b/complex64_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, complex64) // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []complex64) { ret := make([]complex64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []complex64) { + ret := make([]complex64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []complex64, address patricia.IPv6Address) (bool, []complex64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []complex64, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []complex64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []complex64, address patricia.IPv6Add if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []complex64, address patricia.IPv6Add // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []complex64, address patricia.IPv6Add if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/float32_tree/tree_v4.go b/float32_tree/tree_v4.go index e72f762..66fa406 100644 --- a/float32_tree/tree_v4.go +++ b/float32_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, float32) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []float32) { ret := make([]float32, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []float32) { + ret := make([]float32, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []float32, address patricia.IPv4Address) (bool, []float32) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []float32, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []float32) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []float32, address patricia.IPv4Addre if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []float32, address patricia.IPv4Addre // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []float32, address patricia.IPv4Addre if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/float32_tree/tree_v6_generated.go b/float32_tree/tree_v6_generated.go index f35944a..35f9ae1 100644 --- a/float32_tree/tree_v6_generated.go +++ b/float32_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, float32) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []float32) { ret := make([]float32, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []float32) { + ret := make([]float32, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []float32, address patricia.IPv6Address) (bool, []float32) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []float32, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []float32) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []float32, address patricia.IPv6Addre if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []float32, address patricia.IPv6Addre // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []float32, address patricia.IPv6Addre if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/float64_tree/tree_v4.go b/float64_tree/tree_v4.go index a88e4e1..c8cebc8 100644 --- a/float64_tree/tree_v4.go +++ b/float64_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, float64) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []float64) { ret := make([]float64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []float64) { + ret := make([]float64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []float64, address patricia.IPv4Address) (bool, []float64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []float64, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []float64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []float64, address patricia.IPv4Addre if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []float64, address patricia.IPv4Addre // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []float64, address patricia.IPv4Addre if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/float64_tree/tree_v6_generated.go b/float64_tree/tree_v6_generated.go index 6464b29..d29049d 100644 --- a/float64_tree/tree_v6_generated.go +++ b/float64_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, float64) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []float64) { ret := make([]float64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []float64) { + ret := make([]float64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []float64, address patricia.IPv6Address) (bool, []float64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []float64, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []float64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []float64, address patricia.IPv6Addre if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []float64, address patricia.IPv6Addre // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []float64, address patricia.IPv6Addre if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/generics_tree/tree_v4.go b/generics_tree/tree_v4.go index 0982bea..848a383 100644 --- a/generics_tree/tree_v4.go +++ b/generics_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4[T]) FindDeepestTag(address patricia.IPv4Address) (bool, T) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4[T]) FindDeepestTags(address patricia.IPv4Address) (bool, []T) { ret := make([]T, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4[T]) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc[T]) (bool, []T) { + ret := make([]T, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv4Address) (bool, []T) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4[T]) FindDeepestTagsWithFilterAppend(ret []T, address patricia.IPv4Address, filterFunc FilterFunc[T]) (bool, []T) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/generics_tree/tree_v4_test.go b/generics_tree/tree_v4_test.go index f344be9..e94695b 100644 --- a/generics_tree/tree_v4_test.go +++ b/generics_tree/tree_v4_test.go @@ -371,6 +371,17 @@ func TestFindDeepestTags(t *testing.T) { assert.Equal("bar", tags[1]) assert.Equal(2, len(tags)) + v4, _, _ = patricia.ParseIPFromString("1.2.3.5") + found, tags = tree.FindDeepestTagsWithFilter(*v4, func(t string) bool { return t == "foo" }) + assert.True(found) + assert.Equal("foo", tags[0]) + assert.Equal(1, len(tags)) + + v4, _, _ = patricia.ParseIPFromString("1.2.3.5") + found, tags = tree.FindDeepestTagsWithFilter(*v4, func(t string) bool { return t == "nothing" }) + assert.True(found) + assert.Equal(0, len(tags)) + // test searching for an address that has nothing v4, _, _ = patricia.ParseIPFromString("9.9.9.9") found, tags = tree.FindDeepestTags(*v4) diff --git a/generics_tree/tree_v6_generated.go b/generics_tree/tree_v6_generated.go index 49743e7..f2da4a6 100644 --- a/generics_tree/tree_v6_generated.go +++ b/generics_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6[T]) FindDeepestTag(address patricia.IPv6Address) (bool, T) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6[T]) FindDeepestTags(address patricia.IPv6Address) (bool, []T) { ret := make([]T, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6[T]) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc[T]) (bool, []T) { + ret := make([]T, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv6Address) (bool, []T) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6[T]) FindDeepestTagsWithFilterAppend(ret []T, address patricia.IPv6Address, filterFunc FilterFunc[T]) (bool, []T) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6[T]) FindDeepestTagsAppend(ret []T, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int16_tree/tree_v4.go b/int16_tree/tree_v4.go index 0ce93b3..383484a 100644 --- a/int16_tree/tree_v4.go +++ b/int16_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, int16) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []int16) { ret := make([]int16, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int16) { + ret := make([]int16, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []int16, address patricia.IPv4Address) (bool, []int16) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []int16, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int16) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int16, address patricia.IPv4Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int16, address patricia.IPv4Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int16, address patricia.IPv4Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int16_tree/tree_v6_generated.go b/int16_tree/tree_v6_generated.go index f273322..780df61 100644 --- a/int16_tree/tree_v6_generated.go +++ b/int16_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, int16) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []int16) { ret := make([]int16, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int16) { + ret := make([]int16, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []int16, address patricia.IPv6Address) (bool, []int16) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []int16, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int16) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int16, address patricia.IPv6Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int16, address patricia.IPv6Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int16, address patricia.IPv6Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int32_tree/tree_v4.go b/int32_tree/tree_v4.go index 169d955..c43ca12 100644 --- a/int32_tree/tree_v4.go +++ b/int32_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, int32) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []int32) { ret := make([]int32, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int32) { + ret := make([]int32, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []int32, address patricia.IPv4Address) (bool, []int32) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []int32, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int32) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int32, address patricia.IPv4Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int32, address patricia.IPv4Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int32, address patricia.IPv4Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int32_tree/tree_v6_generated.go b/int32_tree/tree_v6_generated.go index 22347eb..1ff195e 100644 --- a/int32_tree/tree_v6_generated.go +++ b/int32_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, int32) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []int32) { ret := make([]int32, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int32) { + ret := make([]int32, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []int32, address patricia.IPv6Address) (bool, []int32) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []int32, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int32) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int32, address patricia.IPv6Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int32, address patricia.IPv6Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int32, address patricia.IPv6Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int64_tree/tree_v4.go b/int64_tree/tree_v4.go index c2eaf6e..dfddf58 100644 --- a/int64_tree/tree_v4.go +++ b/int64_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, int64) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []int64) { ret := make([]int64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int64) { + ret := make([]int64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []int64, address patricia.IPv4Address) (bool, []int64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []int64, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int64, address patricia.IPv4Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int64, address patricia.IPv4Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int64, address patricia.IPv4Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int64_tree/tree_v6_generated.go b/int64_tree/tree_v6_generated.go index c7bc169..20da5a5 100644 --- a/int64_tree/tree_v6_generated.go +++ b/int64_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, int64) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []int64) { ret := make([]int64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int64) { + ret := make([]int64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []int64, address patricia.IPv6Address) (bool, []int64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []int64, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int64, address patricia.IPv6Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int64, address patricia.IPv6Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int64, address patricia.IPv6Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int8_tree/tree_v4.go b/int8_tree/tree_v4.go index 655d5d1..7ac7fec 100644 --- a/int8_tree/tree_v4.go +++ b/int8_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, int8) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []int8) { ret := make([]int8, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int8) { + ret := make([]int8, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []int8, address patricia.IPv4Address) (bool, []int8) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []int8, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int8) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int8, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int8, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int8, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int8_tree/tree_v6_generated.go b/int8_tree/tree_v6_generated.go index 8bfba86..9342b94 100644 --- a/int8_tree/tree_v6_generated.go +++ b/int8_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, int8) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []int8) { ret := make([]int8, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int8) { + ret := make([]int8, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []int8, address patricia.IPv6Address) (bool, []int8) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []int8, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int8) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int8, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int8, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int8, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int_tree/tree_v4.go b/int_tree/tree_v4.go index 07dd096..17a3fda 100644 --- a/int_tree/tree_v4.go +++ b/int_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, int) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []int) { ret := make([]int, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int) { + ret := make([]int, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []int, address patricia.IPv4Address) (bool, []int) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []int, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []int) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []int, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/int_tree/tree_v6_generated.go b/int_tree/tree_v6_generated.go index 95811da..cc732ee 100644 --- a/int_tree/tree_v6_generated.go +++ b/int_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, int) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []int) { ret := make([]int, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int) { + ret := make([]int, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []int, address patricia.IPv6Address) (bool, []int) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []int, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []int) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []int, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/rune_tree/tree_v4.go b/rune_tree/tree_v4.go index bd09944..8a9b0d9 100644 --- a/rune_tree/tree_v4.go +++ b/rune_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, rune) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []rune) { ret := make([]rune, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []rune) { + ret := make([]rune, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []rune, address patricia.IPv4Address) (bool, []rune) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []rune, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []rune) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []rune, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []rune, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []rune, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/rune_tree/tree_v6_generated.go b/rune_tree/tree_v6_generated.go index 2db2fb3..70e9253 100644 --- a/rune_tree/tree_v6_generated.go +++ b/rune_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, rune) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []rune) { ret := make([]rune, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []rune) { + ret := make([]rune, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []rune, address patricia.IPv6Address) (bool, []rune) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []rune, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []rune) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []rune, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []rune, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []rune, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/string_tree/tree_v4.go b/string_tree/tree_v4.go index 11e5254..101116a 100644 --- a/string_tree/tree_v4.go +++ b/string_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, string) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []string) { ret := make([]string, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []string) { + ret := make([]string, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []string, address patricia.IPv4Address) (bool, []string) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []string, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []string) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []string, address patricia.IPv4Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []string, address patricia.IPv4Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []string, address patricia.IPv4Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/string_tree/tree_v6_generated.go b/string_tree/tree_v6_generated.go index d6718d2..4133669 100644 --- a/string_tree/tree_v6_generated.go +++ b/string_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, string) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []string) { ret := make([]string, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []string) { + ret := make([]string, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []string, address patricia.IPv6Address) (bool, []string) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []string, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []string) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []string, address patricia.IPv6Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []string, address patricia.IPv6Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []string, address patricia.IPv6Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/template/tree_v4.go b/template/tree_v4.go index b749d19..8193081 100644 --- a/template/tree_v4.go +++ b/template/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, GeneratedTy // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []GeneratedType) { ret := make([]GeneratedType, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []GeneratedType) { + ret := make([]GeneratedType, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv4Address) (bool, []GeneratedType) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []GeneratedType, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []GeneratedType) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/template/tree_v4_test.go b/template/tree_v4_test.go index 0c52281..3cc1ed2 100644 --- a/template/tree_v4_test.go +++ b/template/tree_v4_test.go @@ -371,6 +371,17 @@ func TestFindDeepestTags(t *testing.T) { assert.Equal("bar", tags[1]) assert.Equal(2, len(tags)) + v4, _, _ = patricia.ParseIPFromString("1.2.3.5") + found, tags = tree.FindDeepestTagsWithFilter(*v4, func(t GeneratedType) bool { return t.(string) == "foo" }) + assert.True(found) + assert.Equal("foo", tags[0]) + assert.Equal(1, len(tags)) + + v4, _, _ = patricia.ParseIPFromString("1.2.3.5") + found, tags = tree.FindDeepestTagsWithFilter(*v4, func(t GeneratedType) bool { return t.(string) == "nothing" }) + assert.True(found) + assert.Equal(0, len(tags)) + // test searching for an address that has nothing v4, _, _ = patricia.ParseIPFromString("9.9.9.9") found, tags = tree.FindDeepestTags(*v4) diff --git a/template/tree_v6_generated.go b/template/tree_v6_generated.go index 064eb33..1b496f3 100644 --- a/template/tree_v6_generated.go +++ b/template/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, GeneratedTy // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []GeneratedType) { ret := make([]GeneratedType, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []GeneratedType) { + ret := make([]GeneratedType, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv6Address) (bool, []GeneratedType) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []GeneratedType, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []GeneratedType) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []GeneratedType, address patricia.IPv if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint16_tree/tree_v4.go b/uint16_tree/tree_v4.go index 28ec5c2..04f7e75 100644 --- a/uint16_tree/tree_v4.go +++ b/uint16_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, uint16) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []uint16) { ret := make([]uint16, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint16) { + ret := make([]uint16, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []uint16, address patricia.IPv4Address) (bool, []uint16) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []uint16, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint16) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint16, address patricia.IPv4Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint16, address patricia.IPv4Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint16, address patricia.IPv4Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint16_tree/tree_v6_generated.go b/uint16_tree/tree_v6_generated.go index e70d90b..28a9ba5 100644 --- a/uint16_tree/tree_v6_generated.go +++ b/uint16_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, uint16) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []uint16) { ret := make([]uint16, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint16) { + ret := make([]uint16, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []uint16, address patricia.IPv6Address) (bool, []uint16) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []uint16, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint16) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint16, address patricia.IPv6Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint16, address patricia.IPv6Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint16, address patricia.IPv6Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint32_tree/tree_v4.go b/uint32_tree/tree_v4.go index 8906288..3e7d5c0 100644 --- a/uint32_tree/tree_v4.go +++ b/uint32_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, uint32) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []uint32) { ret := make([]uint32, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint32) { + ret := make([]uint32, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []uint32, address patricia.IPv4Address) (bool, []uint32) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []uint32, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint32) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint32, address patricia.IPv4Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint32, address patricia.IPv4Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint32, address patricia.IPv4Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint32_tree/tree_v6_generated.go b/uint32_tree/tree_v6_generated.go index 197a24b..3f1ff73 100644 --- a/uint32_tree/tree_v6_generated.go +++ b/uint32_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, uint32) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []uint32) { ret := make([]uint32, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint32) { + ret := make([]uint32, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []uint32, address patricia.IPv6Address) (bool, []uint32) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []uint32, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint32) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint32, address patricia.IPv6Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint32, address patricia.IPv6Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint32, address patricia.IPv6Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint64_tree/tree_v4.go b/uint64_tree/tree_v4.go index b91d4ea..ae045a9 100644 --- a/uint64_tree/tree_v4.go +++ b/uint64_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, uint64) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []uint64) { ret := make([]uint64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint64) { + ret := make([]uint64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []uint64, address patricia.IPv4Address) (bool, []uint64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []uint64, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint64, address patricia.IPv4Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint64, address patricia.IPv4Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint64, address patricia.IPv4Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint64_tree/tree_v6_generated.go b/uint64_tree/tree_v6_generated.go index e5b8549..6591440 100644 --- a/uint64_tree/tree_v6_generated.go +++ b/uint64_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, uint64) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []uint64) { ret := make([]uint64, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint64) { + ret := make([]uint64, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []uint64, address patricia.IPv6Address) (bool, []uint64) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []uint64, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint64) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint64, address patricia.IPv6Addres if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint64, address patricia.IPv6Addres // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint64, address patricia.IPv6Addres if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint8_tree/tree_v4.go b/uint8_tree/tree_v4.go index a017e63..dc11bbf 100644 --- a/uint8_tree/tree_v4.go +++ b/uint8_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, uint8) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []uint8) { ret := make([]uint8, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint8) { + ret := make([]uint8, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []uint8, address patricia.IPv4Address) (bool, []uint8) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []uint8, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint8) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint8, address patricia.IPv4Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint8, address patricia.IPv4Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint8, address patricia.IPv4Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint8_tree/tree_v6_generated.go b/uint8_tree/tree_v6_generated.go index c018bbe..d062ef8 100644 --- a/uint8_tree/tree_v6_generated.go +++ b/uint8_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, uint8) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []uint8) { ret := make([]uint8, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint8) { + ret := make([]uint8, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []uint8, address patricia.IPv6Address) (bool, []uint8) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []uint8, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint8) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint8, address patricia.IPv6Address if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint8, address patricia.IPv6Address // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint8, address patricia.IPv6Address if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint_tree/tree_v4.go b/uint_tree/tree_v4.go index 1a8bf72..dfa4b54 100644 --- a/uint_tree/tree_v4.go +++ b/uint_tree/tree_v4.go @@ -620,12 +620,27 @@ func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, uint) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []uint) { ret := make([]uint, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint) { + ret := make([]uint, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV4) FindDeepestTagsAppend(ret []uint, address patricia.IPv4Address) (bool, []uint) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []uint, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []uint) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint, address patricia.IPv4Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint, address patricia.IPv4Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV4) FindDeepestTagsAppend(ret []uint, address patricia.IPv4Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing diff --git a/uint_tree/tree_v6_generated.go b/uint_tree/tree_v6_generated.go index fcfd8fd..1c881ce 100644 --- a/uint_tree/tree_v6_generated.go +++ b/uint_tree/tree_v6_generated.go @@ -620,12 +620,27 @@ func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, uint) { // - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []uint) { ret := make([]uint, 0) - return t.FindDeepestTagsAppend(ret, address) + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint) { + ret := make([]uint, 0) + return t.FindDeepestTagsWithFilterAppend(ret, address, filterFunc) } // FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match // - appends results to the input slice func (t *TreeV6) FindDeepestTagsAppend(ret []uint, address patricia.IPv6Address) (bool, []uint) { + return t.FindDeepestTagsWithFilterAppend(ret, address, nil) +} + +// FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match +// - appends results to the input slice +// - returns true regardless of the result of the filtering function +func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []uint, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []uint) { root := &t.nodes[1] var found bool var retTagIndex uint @@ -637,7 +652,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint, address patricia.IPv6Address) if address.Length == 0 { // caller just looking for root tags - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } var nodeIndex uint @@ -650,14 +665,14 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint, address patricia.IPv6Address) // traverse the tree for { if nodeIndex == 0 { - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } node := &t.nodes[nodeIndex] matchCount := node.MatchCount(address) if matchCount < node.prefixLength { // didn't match the entire node - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // matched the full node - get its tags, then chop off the bits we've already matched and continue @@ -668,7 +683,7 @@ func (t *TreeV6) FindDeepestTagsAppend(ret []uint, address patricia.IPv6Address) if matchCount == address.Length { // exact match - we're done - return found, t.tagsForNode(ret, retTagIndex, nil) + return found, t.tagsForNode(ret, retTagIndex, filterFunc) } // there's still more address - keep traversing