Show More
@@ -171,7 +171,7 b' class baseset(abstractsmartset):' | |||||
171 | >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
171 | >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] | |
172 | [[0, 4, 6, 7, 3, 5], [6, 7], [0, 4]] |
|
172 | [[0, 4, 6, 7, 3, 5], [6, 7], [0, 4]] | |
173 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
173 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] | |
174 |
['addset', ' |
|
174 | ['addset', 'baseset', 'baseset'] | |
175 |
|
175 | |||
176 | Construct by a list-like: |
|
176 | Construct by a list-like: | |
177 | >>> xs = baseset(x) |
|
177 | >>> xs = baseset(x) | |
@@ -191,18 +191,18 b' class baseset(abstractsmartset):' | |||||
191 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
191 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] | |
192 | ['addset', 'filteredset', 'filteredset'] |
|
192 | ['addset', 'filteredset', 'filteredset'] | |
193 |
|
193 | |||
194 | With sort(): |
|
194 | With sort(), set optimization could be used: | |
195 | >>> xs.sort(reverse=True) |
|
195 | >>> xs.sort(reverse=True) | |
196 | >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
196 | >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] | |
197 | [[7, 6, 4, 0, 5, 3], [7, 6], [4, 0]] |
|
197 | [[7, 6, 4, 0, 5, 3], [7, 6], [4, 0]] | |
198 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
198 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] | |
199 |
['addset', ' |
|
199 | ['addset', 'baseset', 'baseset'] | |
200 |
|
200 | |||
201 | >>> ys.sort() |
|
201 | >>> ys.sort() | |
202 | >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
202 | >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] | |
203 | [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]] |
|
203 | [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]] | |
204 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
204 | >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] | |
205 |
['addset', ' |
|
205 | ['addset', 'baseset', 'baseset'] | |
206 | """ |
|
206 | """ | |
207 | def __init__(self, data=(), datarepr=None, istopo=False): |
|
207 | def __init__(self, data=(), datarepr=None, istopo=False): | |
208 | """ |
|
208 | """ | |
@@ -322,6 +322,22 b' class baseset(abstractsmartset):' | |||||
322 | return self._asclist[0] |
|
322 | return self._asclist[0] | |
323 | return None |
|
323 | return None | |
324 |
|
324 | |||
|
325 | def _fastsetop(self, other, op): | |||
|
326 | # try to use native set operations as fast paths | |||
|
327 | if (type(other) is baseset and '_set' in other.__dict__ and '_set' in | |||
|
328 | self.__dict__ and self._ascending is not None): | |||
|
329 | s = baseset(data=getattr(self._set, op)(other._set)) | |||
|
330 | s._ascending = self._ascending | |||
|
331 | else: | |||
|
332 | s = getattr(super(baseset, self), op)(other) | |||
|
333 | return s | |||
|
334 | ||||
|
335 | def __and__(self, other): | |||
|
336 | return self._fastsetop(other, '__and__') | |||
|
337 | ||||
|
338 | def __sub__(self, other): | |||
|
339 | return self._fastsetop(other, '__sub__') | |||
|
340 | ||||
325 | def __repr__(self): |
|
341 | def __repr__(self): | |
326 | d = {None: '', False: '-', True: '+'}[self._ascending] |
|
342 | d = {None: '', False: '-', True: '+'}[self._ascending] | |
327 | s = _formatsetrepr(self._datarepr) |
|
343 | s = _formatsetrepr(self._datarepr) |
General Comments 0
You need to be logged in to leave comments.
Login now