2174 self._subset.reverse() |
2174 self._subset.reverse() |
2175 |
2175 |
2176 def set(self): |
2176 def set(self): |
2177 return set([r for r in self]) |
2177 return set([r for r in self]) |
2178 |
2178 |
|
2179 class generatorset(object): |
|
2180 """Wrapper structure for generators that provides lazy membership.""" |
|
2181 def __init__(self, gen): |
|
2182 self._gen = gen |
|
2183 self._iter = iter(gen) |
|
2184 self._cache = {} |
|
2185 |
|
2186 def __contains__(self, x): |
|
2187 if x in self._cache: |
|
2188 return self._cache[x] |
|
2189 |
|
2190 while True: |
|
2191 try: |
|
2192 l = self._iter.next() |
|
2193 self._cache[l] = True |
|
2194 if l == x: |
|
2195 return True |
|
2196 except (StopIteration): |
|
2197 break |
|
2198 |
|
2199 self._cache[x] = False |
|
2200 return False |
|
2201 |
|
2202 def __iter__(self): |
|
2203 for item in self._gen: |
|
2204 self._cache[item] = True |
|
2205 yield item |
|
2206 |
|
2207 def set(self): |
|
2208 return self |
|
2209 |
2179 class spanset(object): |
2210 class spanset(object): |
2180 """Duck type for baseset class which represents a range of revisions and |
2211 """Duck type for baseset class which represents a range of revisions and |
2181 can work lazily and without having all the range in memory |
2212 can work lazily and without having all the range in memory |
2182 """ |
2213 """ |
2183 def __init__(self, repo, start=0, end=None): |
2214 def __init__(self, repo, start=0, end=None): |