~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2008 Canonical Ltd
 
1
# (C) 2005 Canonical
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
from bzrlib.tsort import topo_sort
 
19
 
 
20
 
18
21
def max_distance(node, ancestors, distances, root_descendants):
19
22
    """Calculate the max distance to an ancestor.  
20
23
    Return None if not all possible ancestors have known distances"""
122
125
 
123
126
    def add_node(self, node_id, parent_ids):
124
127
        """Add node_id to the graph with parent_ids as its parents."""
125
 
        if len(parent_ids) == 0:
 
128
        if parent_ids == []:
126
129
            self.roots.add(node_id)
127
130
        self._graph_ancestors[node_id] = list(parent_ids)
128
131
        self._ensure_descendant(node_id)
139
142
        """Return a dictionary of graph node:ancestor_list entries."""
140
143
        return dict(self._graph_ancestors.items())
141
144
 
142
 
    def get_ancestry(self, node_id, topo_sorted=True):
 
145
    def get_ancestry(self, node_id):
143
146
        """Return the inclusive ancestors of node_id in topological order."""
144
147
        # maybe optimise this ?
145
 
        from bzrlib.tsort import topo_sort
146
148
        result = {}
147
149
        pending = set([node_id])
148
150
        while len(pending):
153
155
            for parent in parents:
154
156
                if parent not in result and parent not in pending:
155
157
                    pending.add(parent)
156
 
        if not topo_sorted:
157
 
            return result.keys()
158
158
        return topo_sort(result.items())
159
159
 
160
160
    def get_descendants(self):