comparison mercurial/revset.py @ 22722:e8832cf1abf6

abstractsmartset: add a default implementation for min and max This default implementation takes advantage of the fast iterator if available.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 02 Oct 2014 18:59:41 -0500
parents adc43967d401
children d4706faa2061
comparison
equal deleted inserted replaced
22721:adc43967d401 22722:e8832cf1abf6
2246 This is part of the mandatory API for smartset.""" 2246 This is part of the mandatory API for smartset."""
2247 self.sort(reverse=True) 2247 self.sort(reverse=True)
2248 2248
2249 def min(self): 2249 def min(self):
2250 """return the minimum element in the set""" 2250 """return the minimum element in the set"""
2251 raise NotImplementedError() 2251 if self.fastasc is not None:
2252 for r in self.fastasc():
2253 return r
2254 raise ValueError('arg is an empty sequence')
2255 return min(self)
2252 2256
2253 def max(self): 2257 def max(self):
2254 """return the maximum element in the set""" 2258 """return the maximum element in the set"""
2255 raise NotImplementedError() 2259 if self.fastdesc is not None:
2260 for r in self.fastdesc():
2261 return r
2262 raise ValueError('arg is an empty sequence')
2263 return max(self)
2256 2264
2257 def reverse(self): 2265 def reverse(self):
2258 """reverse the expected iteration order""" 2266 """reverse the expected iteration order"""
2259 raise NotImplementedError() 2267 raise NotImplementedError()
2260 2268