Exemple #1
0
        void PrintRoots(ObjectMapReader omap, int type, int maxlevels)
        {
            List <int> path = new List <int> ();
            Dictionary <int, List <int> > roots   = new Dictionary <int, List <int> > ();
            Dictionary <int, int>         visited = new Dictionary <int, int> ();

            foreach (int obj in omap.GetObjectsByType(type))
            {
                FindRoot(omap, visited, path, roots, obj);
                visited.Clear();
            }

            foreach (List <int> ep in roots.Values)
            {
                for (int n = 0; n < ep.Count && n < maxlevels; n++)
                {
                    int ob = ep [n];
                    Console.WriteLine(n + ". " + omap.GetObjectTypeName(ob));
                }
                if (maxlevels < ep.Count)
                {
                    Console.WriteLine("...");
                }
                Console.WriteLine();
                Console.WriteLine("-");
                Console.WriteLine();
            }
        }
Exemple #2
0
        void FindRoot(ObjectMapReader omap, Dictionary <int, int> visited, List <int> path, Dictionary <int, List <int> > roots, int obj)
        {
            if (visited.ContainsKey(obj))
            {
                return;
            }
            visited [obj] = obj;
            path.Add(obj);

            bool hasrefs = false;

            foreach (int oref in omap.GetReferencers(obj))
            {
                hasrefs = true;
                FindRoot(omap, visited, path, roots, oref);
            }

            if (!hasrefs)
            {
                // A root
                List <int> ep = roots [obj];
                if (ep == null)
                {
                    roots [obj] = new List <int> (path);
                }
                else
                {
                    if (ep.Count > path.Count)
                    {
                        roots [obj] = new List <int> (path);
                    }
                }
                Console.WriteLine("found root" + roots.Count + " " + path.Count + " " + omap.GetObjectTypeName(obj));
                foreach (int o in path)
                {
                    Console.Write(omap.GetObjectTypeName(o) + " / ");
                }
                Console.WriteLine();
            }
            path.RemoveAt(path.Count - 1);
        }