github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/structs/transporttrie/string.go (about) 1 package transporttrie 2 3 import "fmt" 4 5 func (t *Trie) String() string { 6 str := "trie:\n" 7 nodes := []*trieNode{t.root} 8 levels := []int{0} 9 parentNames := make([][]byte, 1) 10 parentNames[0] = make([]byte, 0) 11 12 for len(nodes) > 0 { 13 node := nodes[0] 14 level := levels[0] 15 parentName := parentNames[0] 16 17 nodes = nodes[1:] 18 levels = levels[1:] 19 parentNames = parentNames[1:] 20 21 prefix := "-" 22 for i := 0; i < level; i++ { 23 prefix += "-" 24 } 25 str += fmt.Sprintf("%s %q %q %q\n", prefix, parentName, node.name, node.value) 26 names := [][]byte{} 27 for _, v := range node.children { 28 names = append(names, v.name) 29 } 30 parentNames = append(names, parentNames...) 31 nodes = append(node.children, nodes...) 32 for i := 0; i < len(node.children); i++ { 33 levels = append([]int{level + 1}, levels...) 34 } 35 } 36 return str 37 }