Skip to content

Improve performance of set membership testing from set arguments #121795

Description

@HarryLHW

Feature or enhancement

Proposal:

For set s and set elem, the operations elem in s, s.remove(elem), and s.discard(elem) are equivalent to frozenset(elem) in s, s.remove(frozenset(elem)), and s.discard(frozenset(elem)), respectively. This feature is documented in Built-in Types:

Note, the elem argument to the contains(), remove(), and discard() methods may be a set. To support searching for an equivalent frozenset, a temporary one is created from elem.

The implementation can be improved by calculating the hash value directly from the set object (as if it is a frozenset), instead of copying it into a new frozenset before calculating the hash value. The hash function for set is internal use only, and set is still unhashable.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions