Show More
@@ -19,11 +19,13 b' def ancestor(a, b, pfunc):' | |||
|
19 | 19 | return a |
|
20 | 20 | |
|
21 | 21 | # find depth from root of all ancestors |
|
22 | parentcache = {} | |
|
22 | 23 | visit = [a, b] |
|
23 | 24 | depth = {} |
|
24 | 25 | while visit: |
|
25 | 26 | vertex = visit[-1] |
|
26 | 27 | pl = pfunc(vertex) |
|
28 | parentcache[vertex] = pl | |
|
27 | 29 | if not pl: |
|
28 | 30 | depth[vertex] = 0 |
|
29 | 31 | visit.pop() |
@@ -46,7 +48,7 b' def ancestor(a, b, pfunc):' | |||
|
46 | 48 | if n not in seen: |
|
47 | 49 | seen[n] = 1 |
|
48 | 50 | yield (d, n) |
|
49 |
for p in p |
|
|
51 | for p in parentcache[n]: | |
|
50 | 52 | heapq.heappush(h, (depth[p], p)) |
|
51 | 53 | |
|
52 | 54 | def generations(vertex): |
General Comments 0
You need to be logged in to leave comments.
Login now