Skip to content

Commit e4bbbf7

Browse files
committed
printDebug, private method to print a representation of the Trie ...
... for debugging purpose
1 parent 187e480 commit e4bbbf7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

rest/trie/impl.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,38 @@ func (n *node) compress() {
302302
}
303303
}
304304

305+
func printFPadding(padding int, format string, a ...interface{}) {
306+
for i := 0; i < padding; i++ {
307+
fmt.Print(" ")
308+
}
309+
fmt.Printf(format, a...)
310+
}
311+
312+
// Private function for now
313+
func (n *node) printDebug(level int) {
314+
level++
315+
// *splat branch
316+
if n.SplatChild != nil {
317+
printFPadding(level, "*splat\n")
318+
n.SplatChild.printDebug(level)
319+
}
320+
// :param branch
321+
if n.ParamChild != nil {
322+
printFPadding(level, ":param\n")
323+
n.ParamChild.printDebug(level)
324+
}
325+
// #param branch
326+
if n.RelaxedChild != nil {
327+
printFPadding(level, "#relaxed\n")
328+
n.RelaxedChild.printDebug(level)
329+
}
330+
// main branch
331+
for key, node := range n.Children {
332+
printFPadding(level, "\"%s\"\n", key)
333+
node.printDebug(level)
334+
}
335+
}
336+
305337
type Trie struct {
306338
root *node
307339
}
@@ -385,3 +417,10 @@ func (t *Trie) FindRoutesForPath(path string) []*Match {
385417
func (t *Trie) Compress() {
386418
t.root.compress()
387419
}
420+
421+
// XXX Private function for now
422+
func (t *Trie) printDebug() {
423+
fmt.Print("<trie>\n")
424+
t.root.printDebug(0)
425+
fmt.Print("</trie>\n")
426+
}

0 commit comments

Comments
 (0)