-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_iter_test.go
77 lines (62 loc) · 1.37 KB
/
example_iter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//go:build go1.23
// Copyright (c) 2024 Karl Gaissmaier
// SPDX-License-Identifier: MIT
package bart_test
import (
"fmt"
"net/netip"
"github.com/gaissmai/bart"
)
func ExampleTable_AllSorted4_rangeoverfunc() {
rtbl := new(bart.Table[netip.Addr])
for _, item := range input {
rtbl.Insert(item.cidr, item.nextHop)
}
for pfx, val := range rtbl.AllSorted4() {
fmt.Printf("%v\t%v\n", pfx, val)
}
// Output:
// 10.0.0.0/8 9.9.9.9
// 10.0.0.0/24 8.8.8.8
// 10.0.1.0/24 10.0.0.0
// 127.0.0.0/8 127.0.0.1
// 127.0.0.1/32 127.0.0.1
// 169.254.0.0/16 10.0.0.0
// 172.16.0.0/12 8.8.8.8
// 192.168.0.0/16 9.9.9.9
// 192.168.1.0/24 127.0.0.1
}
func ExampleTable_Subnets_rangeoverfunc() {
rtbl := new(bart.Table[netip.Addr])
for _, item := range input {
rtbl.Insert(item.cidr, item.nextHop)
}
cidr := netip.MustParsePrefix("0.0.0.0/1")
for pfx := range rtbl.Subnets(cidr) {
fmt.Printf("%v\n", pfx)
}
// Output:
// 10.0.0.0/8
// 10.0.0.0/24
// 10.0.1.0/24
// 127.0.0.0/8
// 127.0.0.1/32
}
func ExampleTable_Supernets_rangeoverfunc() {
rtbl := new(bart.Table[netip.Addr])
for _, item := range input {
rtbl.Insert(item.cidr, item.nextHop)
}
cidr := netip.MustParsePrefix("2001:db8::/32")
counter := 0
for pfx := range rtbl.Supernets(cidr) {
fmt.Printf("%v\n", pfx)
counter++
if counter >= 2 {
break
}
}
// Output:
// 2001:db8::/32
// 2000::/3
}