##// END OF EJS Templates
ancestor: use set instead of dict
Benoit Boissinot -
r8465:23429ebd default
parent child Browse files
Show More
@@ -42,24 +42,24 b' def ancestor(a, b, pfunc):'
42 # traverse ancestors in order of decreasing distance from root
42 # traverse ancestors in order of decreasing distance from root
43 def ancestors(vertex):
43 def ancestors(vertex):
44 h = [(depth[vertex], vertex)]
44 h = [(depth[vertex], vertex)]
45 seen = {}
45 seen = set()
46 while h:
46 while h:
47 d, n = heapq.heappop(h)
47 d, n = heapq.heappop(h)
48 if n not in seen:
48 if n not in seen:
49 seen[n] = 1
49 seen.add(n)
50 yield (d, n)
50 yield (d, n)
51 for p in parentcache[n]:
51 for p in parentcache[n]:
52 heapq.heappush(h, (depth[p], p))
52 heapq.heappush(h, (depth[p], p))
53
53
54 def generations(vertex):
54 def generations(vertex):
55 sg, s = None, {}
55 sg, s = None, set()
56 for g, v in ancestors(vertex):
56 for g, v in ancestors(vertex):
57 if g != sg:
57 if g != sg:
58 if sg:
58 if sg:
59 yield sg, s
59 yield sg, s
60 sg, s = g, {v:1}
60 sg, s = g, set((v,))
61 else:
61 else:
62 s[v] = 1
62 s.add(v)
63 yield sg, s
63 yield sg, s
64
64
65 x = generations(a)
65 x = generations(a)
General Comments 0
You need to be logged in to leave comments. Login now