##// END OF EJS Templates
revset: changed _iterator() method on addset to work with a given order...
Lucas Moscovicz -
r20722:6894223e default
parent child Browse files
Show More
@@ -2340,14 +2340,60 b' class _addset(object):'
2340 return self._genlist
2340 return self._genlist
2341
2341
2342 def _iterator(self):
2342 def _iterator(self):
2343 """Iterate over both collections without repeating elements
2344
2345 If the ascending attribute is not set, iterate over the first one and
2346 then over the second one checking for membership on the first one so we
2347 dont yield any duplicates.
2348
2349 If the ascending attribute is set, iterate over both collections at the
2350 same time, yielding only one value at a time in the given order.
2351 """
2343 if not self._iter:
2352 if not self._iter:
2344 def gen():
2353 def gen():
2345 for r in self._r1:
2354 if self._ascending is None:
2346 yield r
2355 for r in self._r1:
2347 s = self._r1.set()
2348 for r in self._r2:
2349 if r not in s:
2350 yield r
2356 yield r
2357 s = self._r1.set()
2358 for r in self._r2:
2359 if r not in s:
2360 yield r
2361 else:
2362 iter1 = iter(self._r1)
2363 iter2 = iter(self._r2)
2364
2365 val1 = None
2366 val2 = None
2367
2368 choice = max
2369 if self._ascending:
2370 choice = min
2371 try:
2372 # Consume both iterators in an ordered way until one is
2373 # empty
2374 while True:
2375 if val1 is None:
2376 val1 = iter1.next()
2377 if val2 is None:
2378 val2 = iter2.next()
2379 next = choice(val1, val2)
2380 yield next
2381 if val1 == next:
2382 val1 = None
2383 if val2 == next:
2384 val2 = None
2385 except StopIteration:
2386 # Flush any remaining values and consume the other one
2387 it = iter2
2388 if val1 is not None:
2389 yield val1
2390 it = iter1
2391 elif val2 is not None:
2392 # might have been equality and both are empty
2393 yield val2
2394 for val in it:
2395 yield val
2396
2351 self._iter = _generatorset(gen())
2397 self._iter = _generatorset(gen())
2352
2398
2353 return self._iter
2399 return self._iter
General Comments 0
You need to be logged in to leave comments. Login now