summaryrefslogtreecommitdiff
path: root/__init__.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2006-10-22 00:07:28 +0200
committerSylvain <syt@logilab.fr>2006-10-22 00:07:28 +0200
commit8acc5f576f3c14ed93f383bcfb28e0f351733a97 (patch)
tree2c3cfac5acdcf5515cd15e0a347f4e6b74d643a1 /__init__.py
parentbac7aea7ce9453d90e36e22ec27dcf5af9de70b9 (diff)
downloadlogilab-common-8acc5f576f3c14ed93f383bcfb28e0f351733a97.tar.gz
restore commands
Diffstat (limited to '__init__.py')
-rw-r--r--__init__.py43
1 files changed, 3 insertions, 40 deletions
diff --git a/__init__.py b/__init__.py
index ce49f2b..71a1f1c 100644
--- a/__init__.py
+++ b/__init__.py
@@ -18,6 +18,9 @@ Logilab common libraries
from __future__ import nested_scopes
+# bw compat
+from logilab.common.graph import get_cycles
+
# FIXME: move all those functions in a separated module
def intersection(list1, list2):
@@ -94,46 +97,6 @@ def flatten(iterable, tr_func=None, results=None):
return results
-def get_cycles(graph_dict, vertices=None):
- '''given a dictionnary representing an ordered graph (i.e. key are vertices
- and values is a list of destination vertices representing edges), return a
- list of detected cycles
- '''
- if not graph_dict:
- return ()
- result = []
- if vertices is None:
- vertices = graph_dict.keys()
- for vertice in vertices:
- _get_cycles(graph_dict, vertice, [], result)
- return result
-
-def _get_cycles(graph_dict, vertice=None, path=None, result=None):
- """recursive function doing the real work for get_cycles"""
- if vertice in path:
- cycle = [vertice]
- for i in range(len(path)-1, 0, -1):
- node = path[i]
- if node == vertice:
- break
- cycle.insert(0, node)
- # make a canonical representation
- start_from = min(cycle)
- index = cycle.index(start_from)
- cycle = cycle[index:] + cycle[0:index]
- # append it to result if not already in
- if not cycle in result:
- result.append(cycle)
- return
- path.append(vertice)
- try:
- for node in graph_dict[vertice]:
- _get_cycles(graph_dict, node, path, result)
- except KeyError:
- pass
- path.pop()
-
-
def cached(callableobj, keyarg=None):
"""simple decorator to cache result of method call"""
#print callableobj, keyarg, callableobj.func_code.co_argcount