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