Skip to content

Hash collisions #31

Closed
Closed
@vais

Description

@vais
$ bundle exec opal-repl
>> a = 'A'
=> "A"
>> a.hash
=> "A"
>> a = []
=> []
>> a.hash
=> "A"

Any ideas how to improve on this? Strings in Opal currently hash to themselves, which is what makes it possible for Hash to be very fast in 99.9% of typical use cases. But... the above is not acceptable. This is an open call for suggestions, I guess. Should we include some magic non-printable characters in hash strings on all other objects? I.e. how can we make sure there is no collision between a hash of a String and a hash of another object that happens to hash to the same value as that string? Again, currently:

>> 1.hash
=> "Numeric:1"
>> "Numeric:1".hash
=> "Numeric:1"

😕 🔫

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