New submission from Serhiy Storchaka <[email protected]>:
If the argument of set.issuperset() is not a set, it is first converted to a
set. It is equivalent to the following code:
if not isinstance(other, (set, frozenset)):
other = set(other)
# The following is equivalent to:
# return set.issubset(other, self)
for x in other:
if x not in self
return False
return True
Two drawbacks of this algorithm:
1. It creates a new set, which takes O(len(other)) time and consumes
O(len(set(other))) memory.
2. It needs to iterate other to the end, even if the result is known earlier.
The proposed PR straightforward the code. The C code is now larger, but it no
longer need additional memory, performs less operations and can stop earlier.
----------
components: Interpreter Core
messages: 413075
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Optimize set.issuperset() for non-set argument
type: performance
versions: Python 3.11
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com