Skip to content

Commit 262db2f

Browse files
committed
change dump format
1 parent 552f23e commit 262db2f

File tree

3 files changed

+31
-123
lines changed

3 files changed

+31
-123
lines changed

dumper.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"io"
99
"strconv"
1010
"strings"
11-
12-
"github.com/gaissmai/bart/internal/art"
1311
)
1412

1513
type nodeType byte
@@ -93,8 +91,8 @@ func (n *node[V]) dump(w io.Writer, path stridePath, depth int, is4 bool) {
9391
fmt.Fprintf(w, "%sprefxs(#%d):", indent, nPfxCount)
9492

9593
for _, idx := range allIndices {
96-
octet, pfxLen := art.IdxToPfx(idx)
97-
fmt.Fprintf(w, " %s/%d", octetFmt(octet, is4), pfxLen)
94+
pfx := cidrFromPath(path, depth, is4, idx)
95+
fmt.Fprintf(w, " %s", pfx)
9896
}
9997

10098
fmt.Fprintln(w)
@@ -115,15 +113,15 @@ func (n *node[V]) dump(w io.Writer, path stridePath, depth int, is4 bool) {
115113

116114
if n.children.Len() != 0 {
117115

118-
nodeAddrs := make([]uint, 0, maxItems)
116+
childAddrs := make([]uint, 0, maxItems)
119117
leafAddrs := make([]uint, 0, maxItems)
120118
fringeAddrs := make([]uint, 0, maxItems)
121119

122120
// the node has recursive child nodes or path-compressed leaves
123121
for i, addr := range n.children.All() {
124122
switch n.children.Items[i].(type) {
125123
case *node[V]:
126-
nodeAddrs = append(nodeAddrs, addr)
124+
childAddrs = append(childAddrs, addr)
127125
continue
128126

129127
case *fringeNode[V]:
@@ -184,11 +182,11 @@ func (n *node[V]) dump(w io.Writer, path stridePath, depth int, is4 bool) {
184182
fmt.Fprintln(w)
185183
}
186184

187-
if nodeCount := len(nodeAddrs); nodeCount > 0 {
188-
// print the next nodes
189-
fmt.Fprintf(w, "%snodes(#%d): ", indent, nodeCount)
185+
if childCount := len(childAddrs); childCount > 0 {
186+
// print the next child
187+
fmt.Fprintf(w, "%schilds(#%d):", indent, childCount)
190188

191-
for _, addr := range nodeAddrs {
189+
for _, addr := range childAddrs {
192190
octet := byte(addr)
193191
fmt.Fprintf(w, " %s", octetFmt(octet, is4))
194192
}

dumper_test.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestDumpDefaultRouteV4(t *testing.T) {
4747
### IPv4: size(1), nodes(1), pfxs(1), leaves(0), fringes(0),
4848
[STOP] depth: 0 path: [] / 0
4949
indexs(#1): [1]
50-
prefxs(#1): 0/0
50+
prefxs(#1): 0.0.0.0/0
5151
values(#1): <nil>
5252
`,
5353
})
@@ -64,7 +64,7 @@ func TestDumpDefaultRouteV6(t *testing.T) {
6464
### IPv6: size(1), nodes(1), pfxs(1), leaves(0), fringes(0),
6565
[STOP] depth: 0 path: [] / 0
6666
indexs(#1): [1]
67-
prefxs(#1): 0x00/0
67+
prefxs(#1): ::/0
6868
values(#1): <nil>
6969
`,
7070
})
@@ -91,33 +91,33 @@ func TestDumpSampleV4(t *testing.T) {
9191
[HALF] depth: 0 path: [] / 0
9292
octets(#5): [10 127 169 172 192]
9393
leaves(#2): 169:{169.254.0.0/16, <nil>} 172:{172.16.0.0/12, <nil>}
94-
nodes(#3): 10 127 192
94+
childs(#3): 10 127 192
9595
9696
.[FULL] depth: 1 path: [10] / 8
9797
.indexs(#1): [1]
98-
.prefxs(#1): 0/0
98+
.prefxs(#1): 10.0.0.0/8
9999
.values(#1): <nil>
100100
.octets(#1): [0]
101-
.nodes(#1): 0
101+
.childs(#1): 0
102102
103103
..[STOP] depth: 2 path: [10.0] / 16
104104
..octets(#2): [0 1]
105105
..fringe(#2): 0:{10.0.0.0/24, <nil>} 1:{10.0.1.0/24, <nil>}
106106
107107
.[STOP] depth: 1 path: [127] / 8
108108
.indexs(#1): [1]
109-
.prefxs(#1): 0/0
109+
.prefxs(#1): 127.0.0.0/8
110110
.values(#1): <nil>
111111
.octets(#1): [0]
112112
.leaves(#1): 0:{127.0.0.1/32, <nil>}
113113
114114
.[PATH] depth: 1 path: [192] / 8
115115
.octets(#1): [168]
116-
.nodes(#1): 168
116+
.childs(#1): 168
117117
118118
..[STOP] depth: 2 path: [192.168] / 16
119119
..indexs(#1): [1]
120-
..prefxs(#1): 0/0
120+
..prefxs(#1): 192.168.0.0/16
121121
..values(#1): <nil>
122122
..octets(#1): [1]
123123
..fringe(#1): 1:{192.168.1.0/24, <nil>}
@@ -139,7 +139,7 @@ func TestDumpSampleV6(t *testing.T) {
139139
### IPv6: size(4), nodes(1), pfxs(2), leaves(2), fringes(0),
140140
[STOP] depth: 0 path: [] / 0
141141
indexs(#2): [1 9]
142-
prefxs(#2): 0x00/0 0x20/3
142+
prefxs(#2): ::/0 2000::/3
143143
values(#2): <nil> <nil>
144144
octets(#2): [32 254]
145145
leaves(#2): 0x20:{2001:db8::/32, <nil>} 0xfe:{fe80::/10, <nil>}
@@ -172,41 +172,41 @@ func TestDumpSample(t *testing.T) {
172172
[HALF] depth: 0 path: [] / 0
173173
octets(#5): [10 127 169 172 192]
174174
leaves(#2): 169:{169.254.0.0/16, <nil>} 172:{172.16.0.0/12, <nil>}
175-
nodes(#3): 10 127 192
175+
childs(#3): 10 127 192
176176
177177
.[FULL] depth: 1 path: [10] / 8
178178
.indexs(#1): [1]
179-
.prefxs(#1): 0/0
179+
.prefxs(#1): 10.0.0.0/8
180180
.values(#1): <nil>
181181
.octets(#1): [0]
182-
.nodes(#1): 0
182+
.childs(#1): 0
183183
184184
..[STOP] depth: 2 path: [10.0] / 16
185185
..octets(#2): [0 1]
186186
..fringe(#2): 0:{10.0.0.0/24, <nil>} 1:{10.0.1.0/24, <nil>}
187187
188188
.[STOP] depth: 1 path: [127] / 8
189189
.indexs(#1): [1]
190-
.prefxs(#1): 0/0
190+
.prefxs(#1): 127.0.0.0/8
191191
.values(#1): <nil>
192192
.octets(#1): [0]
193193
.leaves(#1): 0:{127.0.0.1/32, <nil>}
194194
195195
.[PATH] depth: 1 path: [192] / 8
196196
.octets(#1): [168]
197-
.nodes(#1): 168
197+
.childs(#1): 168
198198
199199
..[STOP] depth: 2 path: [192.168] / 16
200200
..indexs(#1): [1]
201-
..prefxs(#1): 0/0
201+
..prefxs(#1): 192.168.0.0/16
202202
..values(#1): <nil>
203203
..octets(#1): [1]
204204
..fringe(#1): 1:{192.168.1.0/24, <nil>}
205205
206206
### IPv6: size(4), nodes(1), pfxs(2), leaves(2), fringes(0),
207207
[STOP] depth: 0 path: [] / 0
208208
indexs(#2): [1 9]
209-
prefxs(#2): 0x00/0 0x20/3
209+
prefxs(#2): ::/0 2000::/3
210210
values(#2): <nil> <nil>
211211
octets(#2): [32 254]
212212
leaves(#2): 0x20:{2001:db8::/32, <nil>} 0xfe:{fe80::/10, <nil>}
@@ -239,38 +239,38 @@ func TestLiteDumpSample(t *testing.T) {
239239
[HALF] depth: 0 path: [] / 0
240240
octets(#5): [10 127 169 172 192]
241241
leaves(#2): 169:{169.254.0.0/16} 172:{172.16.0.0/12}
242-
nodes(#3): 10 127 192
242+
childs(#3): 10 127 192
243243
244244
.[FULL] depth: 1 path: [10] / 8
245245
.indexs(#1): [1]
246-
.prefxs(#1): 0/0
246+
.prefxs(#1): 10.0.0.0/8
247247
.octets(#1): [0]
248-
.nodes(#1): 0
248+
.childs(#1): 0
249249
250250
..[STOP] depth: 2 path: [10.0] / 16
251251
..octets(#2): [0 1]
252252
..fringe(#2): 0:{10.0.0.0/24} 1:{10.0.1.0/24}
253253
254254
.[STOP] depth: 1 path: [127] / 8
255255
.indexs(#1): [1]
256-
.prefxs(#1): 0/0
256+
.prefxs(#1): 127.0.0.0/8
257257
.octets(#1): [0]
258258
.leaves(#1): 0:{127.0.0.1/32}
259259
260260
.[PATH] depth: 1 path: [192] / 8
261261
.octets(#1): [168]
262-
.nodes(#1): 168
262+
.childs(#1): 168
263263
264264
..[STOP] depth: 2 path: [192.168] / 16
265265
..indexs(#1): [1]
266-
..prefxs(#1): 0/0
266+
..prefxs(#1): 192.168.0.0/16
267267
..octets(#1): [1]
268268
..fringe(#1): 1:{192.168.1.0/24}
269269
270270
### IPv6: size(4), nodes(1), pfxs(2), leaves(2), fringes(0),
271271
[STOP] depth: 0 path: [] / 0
272272
indexs(#2): [1 9]
273-
prefxs(#2): 0x00/0 0x20/3
273+
prefxs(#2): ::/0 2000::/3
274274
octets(#2): [32 254]
275275
leaves(#2): 0x20:{2001:db8::/32} 0xfe:{fe80::/10}
276276
`,

my_test.go

-90
This file was deleted.

0 commit comments

Comments
 (0)