summaryrefslogtreecommitdiff
path: root/internal/flamegraph/trie_insert.go
blob: 7748b4ad8a72bb1ad507a1d757b109b81f3f7fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package flamegraph

// insertTriePath follows or creates nodes for frames and adds value at the leaf.
func insertTriePath(root *trieNode, frames []string, value uint64) {
	node := root
	for _, frame := range frames {
		if node.childMap == nil {
			node.childMap = make(map[string]*trieNode)
		}
		child, ok := node.childMap[frame]
		if !ok {
			child = &trieNode{
				name:     frame,
				childMap: make(map[string]*trieNode),
			}
			node.children = append(node.children, child)
			node.childMap[frame] = child
		}
		node = child
	}
	node.value += value
}