##// END OF EJS Templates
addset: do lazy sorting...
Pierre-Yves David -
r22859:513c0ba6 default
parent child Browse files
Show More
@@ -2521,6 +2521,7 b' class addset(abstractsmartset):'
2521 self._iter = None
2521 self._iter = None
2522 self._ascending = ascending
2522 self._ascending = ascending
2523 self._genlist = None
2523 self._genlist = None
2524 self._asclist = None
2524
2525
2525 def __len__(self):
2526 def __len__(self):
2526 return len(self._list)
2527 return len(self._list)
@@ -2560,12 +2561,31 b' class addset(abstractsmartset):'
2560 return gen
2561 return gen
2561
2562
2562 def __iter__(self):
2563 def __iter__(self):
2563 if self._genlist:
2564 if self._ascending is None:
2564 return iter(self._genlist)
2565 if self._genlist:
2565 return iter(self._iterator())
2566 return iter(self._genlist)
2567 return iter(self._iterator())
2568 self._trysetasclist()
2569 if self._ascending:
2570 it = self.fastasc
2571 else:
2572 it = self.fastdesc
2573 if it is None:
2574 # consume the gen and try again
2575 self._list
2576 return iter(self)
2577 return it()
2578
2579 def _trysetasclist(self):
2580 """populate the _asclist attribut if possible and necessary"""
2581 if self._genlist is not None and self._asclist is None:
2582 self._asclist = sorted(self._genlist)
2566
2583
2567 @property
2584 @property
2568 def fastasc(self):
2585 def fastasc(self):
2586 self._trysetasclist()
2587 if self._asclist is not None:
2588 return self._asclist.__iter__
2569 iter1 = self._r1.fastasc
2589 iter1 = self._r1.fastasc
2570 iter2 = self._r2.fastasc
2590 iter2 = self._r2.fastasc
2571 if None in (iter1, iter2):
2591 if None in (iter1, iter2):
@@ -2574,6 +2594,9 b' class addset(abstractsmartset):'
2574
2594
2575 @property
2595 @property
2576 def fastdesc(self):
2596 def fastdesc(self):
2597 self._trysetasclist()
2598 if self._asclist is not None:
2599 return self._asclist.__reversed__
2577 iter1 = self._r1.fastdesc
2600 iter1 = self._r1.fastdesc
2578 iter2 = self._r2.fastdesc
2601 iter2 = self._r2.fastdesc
2579 if None in (iter1, iter2):
2602 if None in (iter1, iter2):
@@ -2633,12 +2656,7 b' class addset(abstractsmartset):'
2633 For this we use the cached list with all the generated values and if we
2656 For this we use the cached list with all the generated values and if we
2634 know they are ascending or descending we can sort them in a smart way.
2657 know they are ascending or descending we can sort them in a smart way.
2635 """
2658 """
2636 if self._ascending is None:
2659 self._ascending = not reverse
2637 self._list.sort(reverse=reverse)
2638 self._ascending = not reverse
2639 else:
2640 if bool(self._ascending) == bool(reverse):
2641 self.reverse()
2642
2660
2643 def isascending(self):
2661 def isascending(self):
2644 return self._ascending is not None and self._ascending
2662 return self._ascending is not None and self._ascending
@@ -2647,8 +2665,9 b' class addset(abstractsmartset):'
2647 return self._ascending is not None and not self._ascending
2665 return self._ascending is not None and not self._ascending
2648
2666
2649 def reverse(self):
2667 def reverse(self):
2650 self._list.reverse()
2668 if self._ascending is None:
2651 if self._ascending is not None:
2669 self._list.reverse()
2670 else:
2652 self._ascending = not self._ascending
2671 self._ascending = not self._ascending
2653
2672
2654 def first(self):
2673 def first(self):
General Comments 0
You need to be logged in to leave comments. Login now