diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-04 12:24:01 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-04 12:24:01 -0400 |
commit | 23a49e346bfb757f57fc3778f069ce9ab710fd5e (patch) | |
tree | d6586ae3d8f09a2af32bbcf69fc278e985638213 /lib/sqlalchemy/topological.py | |
parent | f3fff5bdeb783013da82516b856cb036dfa58cf8 (diff) | |
download | sqlalchemy-23a49e346bfb757f57fc3778f069ce9ab710fd5e.tar.gz |
- further reduce what topological has to do, expects full list of nodes
- fix some side-effect-dependent behaviors in uow. we can now
unconditionally remove "disabled" actions without rewriting
Diffstat (limited to 'lib/sqlalchemy/topological.py')
-rw-r--r-- | lib/sqlalchemy/topological.py | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/lib/sqlalchemy/topological.py b/lib/sqlalchemy/topological.py index 5fc982ae0..bcf47bd64 100644 --- a/lib/sqlalchemy/topological.py +++ b/lib/sqlalchemy/topological.py @@ -26,26 +26,16 @@ __all__ = ['sort'] class _EdgeCollection(object): """A collection of directed edges.""" - def __init__(self): + def __init__(self, edges): self.parent_to_children = util.defaultdict(set) self.child_to_parents = util.defaultdict(set) - - def add(self, edge): - """Add an edge to this collection.""" - - parentnode, childnode = edge - self.parent_to_children[parentnode].add(childnode) - self.child_to_parents[childnode].add(parentnode) - + for parentnode, childnode in edges: + self.parent_to_children[parentnode].add(childnode) + self.child_to_parents[childnode].add(parentnode) + def has_parents(self, node): return node in self.child_to_parents and bool(self.child_to_parents[node]) - def edges_by_parent(self, node): - if node in self.parent_to_children: - return [(node, child) for child in self.parent_to_children[node]] - else: - return [] - def outgoing(self, node): """an iterable returning all nodes reached via node's outgoing edges""" @@ -79,13 +69,9 @@ def sort(tuples, allitems): 'tuples' is a list of tuples representing a partial ordering. """ - edges = _EdgeCollection() + edges = _EdgeCollection(tuples) nodes = set(allitems) - for t in tuples: - nodes.update(t) - edges.add(t) - queue = [] for n in nodes: if not edges.has_parents(n): @@ -106,12 +92,8 @@ def sort(tuples, allitems): def find_cycles(tuples, allitems): # straight from gvr with some mods todo = set(allitems) - edges = _EdgeCollection() + edges = _EdgeCollection(tuples) - for t in tuples: - todo.update(t) - edges.add(t) - output = set() while todo: |