Show More
@@ -2624,10 +2624,8 b' class _generatorset(object):' | |||||
2624 | gen: a generator producing the values for the generatorset. |
|
2624 | gen: a generator producing the values for the generatorset. | |
2625 | """ |
|
2625 | """ | |
2626 | self._gen = gen |
|
2626 | self._gen = gen | |
2627 | self._iter = iter(gen) |
|
|||
2628 | self._cache = {} |
|
2627 | self._cache = {} | |
2629 | self._genlist = baseset([]) |
|
2628 | self._genlist = baseset([]) | |
2630 | self._iterated = False |
|
|||
2631 | self._finished = False |
|
2629 | self._finished = False | |
2632 |
|
2630 | |||
2633 | def __contains__(self, x): |
|
2631 | def __contains__(self, x): | |
@@ -2639,28 +2637,30 b' class _generatorset(object):' | |||||
2639 | if l == x: |
|
2637 | if l == x: | |
2640 | return True |
|
2638 | return True | |
2641 |
|
2639 | |||
2642 | self._finished = True |
|
|||
2643 | self._cache[x] = False |
|
2640 | self._cache[x] = False | |
2644 | return False |
|
2641 | return False | |
2645 |
|
2642 | |||
2646 | def __iter__(self): |
|
2643 | def __iter__(self): | |
2647 |
if self._ |
|
2644 | if self._finished: | |
2648 | # At least a part of the list should be cached if iteration has |
|
2645 | for x in self._genlist: | |
2649 | # started over the generatorset. |
|
2646 | yield x | |
2650 | for l in self._genlist: |
|
2647 | return | |
2651 | yield l |
|
2648 | ||
2652 |
|
2649 | i = 0 | ||
2653 | for item in self._consumegen(): |
|
2650 | genlist = self._genlist | |
2654 | yield item |
|
2651 | consume = self._consumegen() | |
|
2652 | while True: | |||
|
2653 | if i < len(genlist): | |||
|
2654 | yield genlist[i] | |||
|
2655 | else: | |||
|
2656 | yield consume.next() | |||
|
2657 | i += 1 | |||
2655 |
|
2658 | |||
2656 | def _consumegen(self): |
|
2659 | def _consumegen(self): | |
2657 | self._iterated = True |
|
|||
2658 |
|
||||
2659 | for item in self._gen: |
|
2660 | for item in self._gen: | |
2660 | self._cache[item] = True |
|
2661 | self._cache[item] = True | |
2661 | self._genlist.append(item) |
|
2662 | self._genlist.append(item) | |
2662 | yield item |
|
2663 | yield item | |
2663 |
|
||||
2664 | self._finished = True |
|
2664 | self._finished = True | |
2665 |
|
2665 | |||
2666 | def set(self): |
|
2666 | def set(self): |
General Comments 0
You need to be logged in to leave comments.
Login now