tree_debug.go 561 B

1234567891011121314151617181920212223242526272829303132
  1. // +build debug
  2. package search
  3. import "fmt"
  4. func (t *Tree) Print() {
  5. if t.root.item == nil {
  6. fmt.Println("/")
  7. } else {
  8. fmt.Printf("/:%#v\n", t.root.item)
  9. }
  10. printNode(t.root, 1)
  11. }
  12. func printNode(n *node, depth int) {
  13. indent := make([]byte, depth)
  14. for i := 0; i < len(indent); i++ {
  15. indent[i] = '\t'
  16. }
  17. for _, children := range n.children {
  18. for k, v := range children {
  19. if v.item == nil {
  20. fmt.Printf("%s%s\n", string(indent), k)
  21. } else {
  22. fmt.Printf("%s%s:%#v\n", string(indent), k, v.item)
  23. }
  24. printNode(v, depth+1)
  25. }
  26. }
  27. }