##// 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 def ancestor(a, b, pfunc):
42 42 # traverse ancestors in order of decreasing distance from root
43 43 def ancestors(vertex):
44 44 h = [(depth[vertex], vertex)]
45 seen = {}
45 seen = set()
46 46 while h:
47 47 d, n = heapq.heappop(h)
48 48 if n not in seen:
49 seen[n] = 1
49 seen.add(n)
50 50 yield (d, n)
51 51 for p in parentcache[n]:
52 52 heapq.heappush(h, (depth[p], p))
53 53
54 54 def generations(vertex):
55 sg, s = None, {}
55 sg, s = None, set()
56 56 for g, v in ancestors(vertex):
57 57 if g != sg:
58 58 if sg:
59 59 yield sg, s
60 sg, s = g, {v:1}
60 sg, s = g, set((v,))
61 61 else:
62 s[v] = 1
62 s.add(v)
63 63 yield sg, s
64 64
65 65 x = generations(a)
General Comments 0
You need to be logged in to leave comments. Login now