Kaynağa Gözat

Cleans up comments/naming regarding TrimTree

Wade Simba Khadder 9 yıl önce
ebeveyn
işleme
c577814d78
2 değiştirilmiş dosya ile 24 ekleme ve 15 silme
  1. 21
    12
      internal/graph/graph.go
  2. 3
    3
      internal/graph/graph_test.go

+ 21
- 12
internal/graph/graph.go Dosyayı Görüntüle

@@ -141,10 +141,18 @@ func (i *NodeInfo) NameComponents() []string {
141 141
 // report entries with the same info.
142 142
 type NodeMap map[NodeInfo]*Node
143 143
 
144
-// NodeSet maps is a collection of node info structs.
144
+// NodeSet is a collection of node info structs.
145 145
 type NodeSet map[NodeInfo]bool
146 146
 
147
-type nodePtrSet map[*Node]bool
147
+// NodePtrSet is a collection of Nodes. Trimming a graph or tree requires a set
148
+// of objects that uniquely identify which nodes to keep. In a graph, NodeInfo
149
+// works as a unique identifier; however, in a tree, multiple nodes may share
150
+// identical NodeInfos. *Node do uniquely identify nodes so we can use those
151
+// instead.Though *Node also uniquely identify nodes in a Graph, we currently
152
+// rebuild Graphs from scratch using only the NodeSet when trimming, so there
153
+// would not be the required context of the initial graph to allow for the use
154
+// of *Node to identify the nodes.
155
+type NodePtrSet map[*Node]bool
148 156
 
149 157
 // FindOrInsertNode takes the info for a node and either returns a matching node
150 158
 // from the node map if one exists, or adds one to the map if one does not.
@@ -335,7 +343,7 @@ func newTree(prof *profile.Profile, o *Options) (g *Graph) {
335 343
 
336 344
 // Trims a Graph that is in forest form to contain only the nodes in kept. This
337 345
 // will not work correctly in the case that a node has multiple parents.
338
-func (g *Graph) TrimTree(kept nodePtrSet) {
346
+func (g *Graph) TrimTree(kept NodePtrSet) {
339 347
 	// Creates a new list of nodes
340 348
 	oldNodes := g.Nodes
341 349
 	g.Nodes = make(Nodes, 0, len(kept))
@@ -600,9 +608,9 @@ func (g *Graph) DiscardLowFrequencyNodes(nodeCutoff int64) NodeSet {
600 608
 
601 609
 // discardLowFrequencyNodePtrs returns a NodePtrSet of nodes at or over a
602 610
 // specific cum value cutoff.
603
-func (g *Graph) DiscardLowFrequencyNodePtrs(nodeCutoff int64) nodePtrSet {
604
-	cutNodes := getNodesWithCumCutoff(g.Nodes, nodeCutoff)
605
-	kept := make(nodePtrSet, len(cutNodes))
611
+func (g *Graph) DiscardLowFrequencyNodePtrs(nodeCutoff int64) NodePtrSet {
612
+	cutNodes := getNodesAboveCumCutoff(g.Nodes, nodeCutoff)
613
+	kept := make(NodePtrSet, len(cutNodes))
606 614
 	for _, n := range cutNodes {
607 615
 		kept[n] = true
608 616
 	}
@@ -610,7 +618,7 @@ func (g *Graph) DiscardLowFrequencyNodePtrs(nodeCutoff int64) nodePtrSet {
610 618
 }
611 619
 
612 620
 func makeNodeSet(nodes Nodes, nodeCutoff int64) NodeSet {
613
-	cutNodes := getNodesWithCumCutoff(nodes, nodeCutoff)
621
+	cutNodes := getNodesAboveCumCutoff(nodes, nodeCutoff)
614 622
 	kept := make(NodeSet, len(cutNodes))
615 623
 	for _, n := range cutNodes {
616 624
 		kept[n.Info] = true
@@ -618,8 +626,9 @@ func makeNodeSet(nodes Nodes, nodeCutoff int64) NodeSet {
618 626
 	return kept
619 627
 }
620 628
 
621
-// Returns all the nodes who have a Cum value greater than or equal to cutoff
622
-func getNodesWithCumCutoff(nodes Nodes, nodeCutoff int64) Nodes {
629
+// getNodesAboveCumCutoff returns all the nodes who have a Cum value greater
630
+// than or equal to cutoff
631
+func getNodesAboveCumCutoff(nodes Nodes, nodeCutoff int64) Nodes {
623 632
 	cutoffNodes := make(Nodes, 0, len(nodes))
624 633
 	for _, n := range nodes {
625 634
 		if abs64(n.Cum) < nodeCutoff {
@@ -682,9 +691,9 @@ func (g *Graph) SortNodes(cum bool, visualMode bool) {
682 691
 	}
683 692
 }
684 693
 
685
-// selectTopNodePtrs returns a set of the top maxNodes *Node in a graph.
686
-func (g *Graph) SelectTopNodePtrs(maxNodes int, visualMode bool) nodePtrSet {
687
-	set := make(nodePtrSet)
694
+// SelectTopNodePtrs returns a set of the top maxNodes *Node in a graph.
695
+func (g *Graph) SelectTopNodePtrs(maxNodes int, visualMode bool) NodePtrSet {
696
+	set := make(NodePtrSet)
688 697
 	for _, node := range g.selectTopNodes(maxNodes, visualMode) {
689 698
 		set[node] = true
690 699
 	}

+ 3
- 3
internal/graph/graph_test.go Dosyayı Görüntüle

@@ -109,7 +109,7 @@ type ExpectedNode struct {
109 109
 type TrimTreeTestCase struct {
110 110
 	Initial  *Graph
111 111
 	Expected []ExpectedNode
112
-	Keep     nodePtrSet
112
+	Keep     NodePtrSet
113 113
 }
114 114
 
115 115
 // Makes the edge from parent to child residual
@@ -143,9 +143,9 @@ func createEmptyNode() *Node {
143 143
 }
144 144
 
145 145
 // Creates an array of ExpectedNodes from nodes.
146
-func createExpectedNodes(nodes ...*Node) ([]ExpectedNode, nodePtrSet) {
146
+func createExpectedNodes(nodes ...*Node) ([]ExpectedNode, NodePtrSet) {
147 147
 	Expected := make([]ExpectedNode, len(nodes))
148
-	Keep := make(nodePtrSet, len(nodes))
148
+	Keep := make(NodePtrSet, len(nodes))
149 149
 
150 150
 	for i, node := range nodes {
151 151
 		Expected[i] = ExpectedNode{