Show More
@@ -2325,7 +2325,7 b' class addset(object):' | |||||
2325 | for r in self._r2: |
|
2325 | for r in self._r2: | |
2326 | if r not in s: |
|
2326 | if r not in s: | |
2327 | yield r |
|
2327 | yield r | |
2328 | self._iter = generatorset(gen()) |
|
2328 | self._iter = _generatorset(gen()) | |
2329 |
|
2329 | |||
2330 | return self._iter |
|
2330 | return self._iter | |
2331 |
|
2331 | |||
@@ -2336,11 +2336,16 b' class addset(object):' | |||||
2336 | def __contains__(self, x): |
|
2336 | def __contains__(self, x): | |
2337 | return x in self._r1 or x in self._r2 |
|
2337 | return x in self._r1 or x in self._r2 | |
2338 |
|
2338 | |||
2339 | class generatorset(object): |
|
2339 | class _generatorset(object): | |
2340 | """Wrapper structure for generators that provides lazy membership and can |
|
2340 | """Wrap a generator for lazy iteration | |
|
2341 | ||||
|
2342 | Wrapper structure for generators that provides lazy membership and can | |||
2341 | be iterated more than once. |
|
2343 | be iterated more than once. | |
2342 | When asked for membership it generates values until either it finds the |
|
2344 | When asked for membership it generates values until either it finds the | |
2343 | requested one or has gone through all the elements in the generator |
|
2345 | requested one or has gone through all the elements in the generator | |
|
2346 | ||||
|
2347 | This class does not duck-type baseset and it's only supposed to be used | |||
|
2348 | internally | |||
2344 | """ |
|
2349 | """ | |
2345 | def __init__(self, gen): |
|
2350 | def __init__(self, gen): | |
2346 | self._gen = gen |
|
2351 | self._gen = gen | |
@@ -2386,8 +2391,8 b' class generatorset(object):' | |||||
2386 | continue |
|
2391 | continue | |
2387 | self._genlist.sort(reverse=reverse) |
|
2392 | self._genlist.sort(reverse=reverse) | |
2388 |
|
2393 | |||
2389 | class ascgeneratorset(generatorset): |
|
2394 | class ascgeneratorset(_generatorset): | |
2390 | """ Same structure as generatorset but stops iterating after it goes past |
|
2395 | """ Same structure as _generatorset but stops iterating after it goes past | |
2391 | the value when asked for membership and the element is not contained |
|
2396 | the value when asked for membership and the element is not contained | |
2392 | """ |
|
2397 | """ | |
2393 | def __contains__(self, x): |
|
2398 | def __contains__(self, x): | |
@@ -2403,8 +2408,8 b' class ascgeneratorset(generatorset):' | |||||
2403 | self._cache[x] = False |
|
2408 | self._cache[x] = False | |
2404 | return False |
|
2409 | return False | |
2405 |
|
2410 | |||
2406 | class descgeneratorset(generatorset): |
|
2411 | class descgeneratorset(_generatorset): | |
2407 | """ Same structure as generatorset but stops iterating after it goes past |
|
2412 | """ Same structure as _generatorset but stops iterating after it goes past | |
2408 | the value when asked for membership and the element is not contained |
|
2413 | the value when asked for membership and the element is not contained | |
2409 | """ |
|
2414 | """ | |
2410 | def __contains__(self, x): |
|
2415 | def __contains__(self, x): |
General Comments 0
You need to be logged in to leave comments.
Login now