Skip to content

O(1) string comparisons #486

Closed as not planned
Closed as not planned
@Fidget-Spinner

Description

@Fidget-Spinner

Random thought I had:

Many strings in CPython are hashed, and their hashes are stored in the string object iself so they don't have to re-computed.

We can make use of those hashes to compare strings.

So
s1 == s2 will fail in O(1) time if their hashes are not equal. Else even if their hashes are equal we have to do a full comparison in case of hash collision.

This shouldn't require much more code, but it also shouldn't move pyperformance. I just thought it would be interesting. Thoughts anyone?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions