Show More
@@ -107,28 +107,24 b' def symmetricdifference(a, b, pfunc):' | |||||
107 |
|
107 | |||
108 | visit = [-a, -b] |
|
108 | visit = [-a, -b] | |
109 | heapq.heapify(visit) |
|
109 | heapq.heapify(visit) | |
110 |
|
|
110 | interesting = len(visit) | |
111 | ret = [] |
|
|||
112 |
|
111 | |||
113 |
while |
|
112 | while interesting: | |
114 | r = -heapq.heappop(visit) |
|
113 | r = -heapq.heappop(visit) | |
115 |
|
|
114 | if colors[r] != ALLCOLORS: | |
116 | n_wanted -= wanted |
|
115 | interesting -= 1 | |
117 | if wanted: |
|
|||
118 | ret.append(r) |
|
|||
119 |
|
116 | |||
120 | for p in pfunc(r): |
|
117 | for p in pfunc(r): | |
121 | if p not in colors: |
|
118 | if p not in colors: | |
122 | # first time we see p; add it to visit |
|
119 | # first time we see p; add it to visit | |
123 | n_wanted += wanted |
|
|||
124 | colors[p] = colors[r] |
|
120 | colors[p] = colors[r] | |
|
121 | if colors[p] != ALLCOLORS: | |||
|
122 | interesting += 1 | |||
125 | heapq.heappush(visit, -p) |
|
123 | heapq.heappush(visit, -p) | |
126 | elif colors[p] != ALLCOLORS and colors[p] != colors[r]: |
|
124 | elif colors[p] != ALLCOLORS and colors[p] != colors[r]: | |
127 | # at first we thought we wanted p, but now |
|
125 | # at first we thought we wanted p, but now | |
128 | # we know we don't really want it |
|
126 | # we know we don't really want it | |
129 | n_wanted -= 1 |
|
|||
130 | colors[p] |= colors[r] |
|
127 | colors[p] |= colors[r] | |
|
128 | interesting -= 1 | |||
131 |
|
129 | |||
132 | del colors[r] |
|
130 | return [r for r in colors if colors[r] != ALLCOLORS] | |
133 |
|
||||
134 | return ret |
|
General Comments 0
You need to be logged in to leave comments.
Login now