##// END OF EJS Templates
revset: added order methods to lazyset classes...
Lucas Moscovicz -
r20657:379e89e4 default
parent child Browse files
Show More
@@ -2146,6 +2146,12 b' class baseset(list):'
2146 super(baseset, self).__init__(data)
2146 super(baseset, self).__init__(data)
2147 self._set = None
2147 self._set = None
2148
2148
2149 def ascending(self):
2150 self.sort()
2151
2152 def descending(self):
2153 self.sort(reverse=True)
2154
2149 def set(self):
2155 def set(self):
2150 if not self._set:
2156 if not self._set:
2151 self._set = set(self)
2157 self._set = set(self)
@@ -2181,6 +2187,12 b' class lazyset(object):'
2181 self._condition = condition
2187 self._condition = condition
2182 self._cache = {}
2188 self._cache = {}
2183
2189
2190 def ascending(self):
2191 self._subset.sort()
2192
2193 def descending(self):
2194 self._subset.sort(reverse=True)
2195
2184 def __contains__(self, x):
2196 def __contains__(self, x):
2185 c = self._cache
2197 c = self._cache
2186 if x not in c:
2198 if x not in c:
@@ -2249,6 +2261,14 b' class orderedlazyset(lazyset):'
2249 def filter(self, l):
2261 def filter(self, l):
2250 return orderedlazyset(self, l, ascending=self._ascending)
2262 return orderedlazyset(self, l, ascending=self._ascending)
2251
2263
2264 def ascending(self):
2265 if not self._ascending:
2266 self.reverse()
2267
2268 def descending(self):
2269 if self._ascending:
2270 self.reverse()
2271
2252 def __and__(self, x):
2272 def __and__(self, x):
2253 return orderedlazyset(self, lambda r: r in x,
2273 return orderedlazyset(self, lambda r: r in x,
2254 ascending=self._ascending)
2274 ascending=self._ascending)
@@ -2257,6 +2277,10 b' class orderedlazyset(lazyset):'
2257 return orderedlazyset(self, lambda r: r not in x,
2277 return orderedlazyset(self, lambda r: r not in x,
2258 ascending=self._ascending)
2278 ascending=self._ascending)
2259
2279
2280 def reverse(self):
2281 self._subset.reverse()
2282 self._ascending = not self._ascending
2283
2260 class generatorset(object):
2284 class generatorset(object):
2261 """Wrapper structure for generators that provides lazy membership and can
2285 """Wrapper structure for generators that provides lazy membership and can
2262 be iterated more than once.
2286 be iterated more than once.
@@ -2342,6 +2366,14 b' class spanset(object):'
2342 self._end = len(repo)
2366 self._end = len(repo)
2343 self._hiddenrevs = repo.changelog.filteredrevs
2367 self._hiddenrevs = repo.changelog.filteredrevs
2344
2368
2369 def ascending(self):
2370 if self._start > self._end:
2371 self.reverse()
2372
2373 def descending(self):
2374 if self._start < self._end:
2375 self.reverse()
2376
2345 def _contained(self, rev):
2377 def _contained(self, rev):
2346 return (rev <= self._start and rev > self._end) or (rev >= self._start
2378 return (rev <= self._start and rev > self._end) or (rev >= self._start
2347 and rev < self._end)
2379 and rev < self._end)
General Comments 0
You need to be logged in to leave comments. Login now