mirror of
https://github.com/python/cpython.git
synced 2025-10-16 03:40:58 +00:00
Sped intersection by large factors (3-5x faster than before on sets of
cardinality 500; and the smaller the intersection, the bigger the speedup).
This commit is contained in:
parent
4a2f91e302
commit
d33e6be59d
1 changed files with 2 additions and 7 deletions
|
@ -176,13 +176,8 @@ class BaseSet(object):
|
||||||
little, big = self, other
|
little, big = self, other
|
||||||
else:
|
else:
|
||||||
little, big = other, self
|
little, big = other, self
|
||||||
result = self.__class__()
|
common = filter(big._data.has_key, little._data.iterkeys())
|
||||||
data = result._data
|
return self.__class__(common)
|
||||||
value = True
|
|
||||||
for elt in little:
|
|
||||||
if elt in big:
|
|
||||||
data[elt] = value
|
|
||||||
return result
|
|
||||||
|
|
||||||
def intersection(self, other):
|
def intersection(self, other):
|
||||||
"""Return the intersection of two sets as a new set.
|
"""Return the intersection of two sets as a new set.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue