abstractsmartset: add a default implementation for min and max
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 02 Oct 2014 18:59:41 -0500
changeset 22722 e8832cf1abf6
parent 22721 adc43967d401
child 22723 d4706faa2061
abstractsmartset: add a default implementation for min and max This default implementation takes advantage of the fast iterator if available.
mercurial/revset.py
--- a/mercurial/revset.py	Thu Oct 02 18:52:09 2014 -0500
+++ b/mercurial/revset.py	Thu Oct 02 18:59:41 2014 -0500
@@ -2248,11 +2248,19 @@
 
     def min(self):
         """return the minimum element in the set"""
-        raise NotImplementedError()
+        if self.fastasc is not None:
+            for r in self.fastasc():
+                return r
+            raise ValueError('arg is an empty sequence')
+        return min(self)
 
     def max(self):
         """return the maximum element in the set"""
-        raise NotImplementedError()
+        if self.fastdesc is not None:
+            for r in self.fastdesc():
+                return r
+            raise ValueError('arg is an empty sequence')
+        return max(self)
 
     def reverse(self):
         """reverse the expected iteration order"""