Show More
@@ -42,24 +42,24 b' 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 |
|
|
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, |
|
|
60 | sg, s = g, set((v,)) | |
|
61 | 61 | else: |
|
62 |
s |
|
|
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