예제 #1
0
파일: ABGraph.cs 프로젝트: nnoldman/FFF
    List <ABGraphNode> CreateGraph(Dictionary <string, ABGraphNode> nodeMap)
    {
        List <ABGraphNode> ret = new List <ABGraphNode>();

        while (nodeMap.Count > 0)
        {
            var         kv      = nodeMap.First();
            ABGraphNode node    = kv.Value;
            ABGraphNode outNode = null;
            if (IsOnlyOneOrZeroParentNode(node, out outNode))
            {
                if (outNode.children.Count > 0)
                {
                    foreach (var child in outNode.GetAllChildren(null))
                    {
                        nodeMap.Remove(child.path);
                    }
                }
            }
            else
            {
                while (outNode.parents.Count > 0)
                {
                    outNode.parents[0].RemoveChild(outNode);
                }
                var children = outNode.GetAllChildren();
                foreach (var child in children)
                {
                    ABGraphNode childoutnode = null;
                    if (IsOnlyOneOrZeroParentNode(child, out childoutnode))
                    {
                        nodeMap.Remove(child.path);
                    }
                }
            }
            nodeMap.Remove(outNode.path);
            Debug.Assert(!ret.Contains(outNode));
            ret.Add(outNode);
        }

        int nodecount = 0;

        foreach (var node in ret)
        {
            Debug.Assert(node.parents.Count <= 1);
            var children = node.GetAllChildren();
            nodecount += children.Count + 1;
            foreach (var child in children)
            {
                Debug.Assert(child.parents.Count == 1);
            }
        }

        Debug.Assert(nodecount == mRawResourceMap.Count);

        return(ret);
    }
예제 #2
0
파일: ABGraph.cs 프로젝트: nnoldman/FFF
    bool IsOnlyOneOrZeroParentNode(ABGraphNode node, out ABGraphNode ret, List <ABGraphNode> closedList = null)
    {
        if (node.parents.Count > 1)
        {
            ret = node;
            return(false);
        }

        if (closedList == null)
        {
            closedList = new List <ABGraphNode>();
        }

        if (node.children.Count > 0)
        {
            var children = node.GetAllChildren(closedList);
            foreach (var child in children)
            {
                if (!IsOnlyOneOrZeroParentNode(child, out ret, closedList))
                {
                    return(false);
                }
            }
        }
        if (node.parents.Count == 0)
        {
            ret = node;
            closedList.Add(node);
            return(true);
        }
        else
        {
            closedList.Add(node);
            ABGraphNode parent   = node.parents[0];
            var         children = parent.GetAllChildren(closedList);
            foreach (var child in children)
            {
                if (!IsOnlyOneOrZeroParentNode(child, out ret, closedList))
                {
                    return(false);
                }
            }
            closedList.Add(parent);
            return(IsOnlyOneOrZeroParentNode(parent, out ret, closedList));
        }
    }