コード例 #1
0
        public void AddEdge(string fromVertexString, string toVertexString, int weight)
        {
            Vertex fromVertex = graph.FindOrCreateVertex(fromVertexString, null);
            Vertex toVertex   = graph.FindOrCreateVertex(toVertexString, null);
            Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);

            edge.AddWeight(weight);
        }
コード例 #2
0
        internal Graph BuildTypeGraph()
        {
            if (graph == null || FilterForm.filterVersion != graphFilterVersion)
            {
                graph              = new Graph(this);
                graph.graphType    = Graph.GraphType.HeapGraph;
                graphFilterVersion = FilterForm.filterVersion;
            }
            else
            {
                foreach (Vertex v in graph.vertices.Values)
                {
                    if (v.weightHistory == null)
                    {
                        v.weightHistory = new int[1];
                    }
                    else
                    {
                        int[] weightHistory = v.weightHistory;
                        if (weightHistory.Length < historyDepth)
                        {
                            v.weightHistory = new int[weightHistory.Length + 1];
                        }
                        for (int i = v.weightHistory.Length - 1; i > 0; i--)
                        {
                            v.weightHistory[i] = weightHistory[i - 1];
                        }
                    }
                    v.weightHistory[0] = v.weight;
                    v.weight           = v.incomingWeight = v.outgoingWeight = v.basicWeight = v.count = 0;
                    foreach (Edge e in v.outgoingEdges.Values)
                    {
                        e.weight = 0;
                    }
                }
            }

            GcType   rootType   = GetOrCreateGcType("<root>");
            GcObject rootObject = GetOrCreateObject(0);

            rootObject.type       = rootType;
            rootObject.references = roots;

            foreach (GcObject gcObject in idToObject.Values)
            {
                gcObject.level  = int.MaxValue;
                gcObject.vertex = null;
            }

            AssignLevel(null, rootObject, 0);

            AssignInterestLevels();

            int index = 0;

            foreach (GcType gcType in typeNameToGcType.Values)
            {
                gcType.index = index++;
            }
            GcType[] gcTypes = new GcType[index];
            typeHintTable = new int[index];

            foreach (GcType gcType in typeNameToGcType.Values)
            {
                gcTypes[gcType.index] = gcType;
            }

            Vertex[] pathFromRoot = new Vertex[32];
            foreach (GcObject gcObject in idToObject.Values)
            {
                if (gcObject.level == int.MaxValue ||
                    (gcObject.interestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                {
                    continue;
                }

                while (pathFromRoot.Length < gcObject.level + 1)
                {
                    pathFromRoot = new Vertex[pathFromRoot.Length * 2];
                }

                for (GcObject pathObject = gcObject; pathObject != null; pathObject = pathObject.parent)
                {
                    if ((pathObject.interestLevel & (InterestLevel.Interesting | InterestLevel.Display)) == InterestLevel.Ignore)
                    {
                        pathFromRoot[pathObject.level] = null;
                    }
                    else
                    {
                        pathFromRoot[pathObject.level] = FindVertex(pathObject, graph);
                    }
                }

                int levels = 0;
                for (int i = 0; i <= gcObject.level; i++)
                {
                    if (pathFromRoot[i] != null)
                    {
                        pathFromRoot[levels++] = pathFromRoot[i];
                    }
                }

                levels = Vertex.SqueezeOutRepetitions(pathFromRoot, levels);

                for (int i = 0; i < levels - 1; i++)
                {
                    Vertex fromVertex = pathFromRoot[i];
                    Vertex toVertex   = pathFromRoot[i + 1];
                    Edge   edge       = graph.FindOrCreateEdge(fromVertex, toVertex);
                    edge.AddWeight(gcObject.size);
                }

                Vertex thisVertex = pathFromRoot[levels - 1];
                thisVertex.basicWeight += gcObject.size;
                thisVertex.count       += 1;
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                if (v.weight < v.outgoingWeight)
                {
                    v.weight = v.outgoingWeight;
                }
                if (v.weight < v.incomingWeight)
                {
                    v.weight = v.incomingWeight;
                }
                if (v.weightHistory == null)
                {
                    v.weightHistory = new int[1];
                }
            }

            foreach (Vertex v in graph.vertices.Values)
            {
                v.active = true;
            }
            graph.BottomVertex.active = false;

            return(graph);
        }