Skip to content

hashCode function in util.HashMap returns same value for an integer and a string containing same integer #28

@patrickwestphal

Description

@patrickwestphal

The hashCode function of the util.HashMap class generates the same hash for, e.g. 23 and '23' (integer and string type, respectively). In this respect the function behaves differently than many other hash functions, e.g. in
Node

> var md5 = require('MD5');
undefined
> md5(23)
'1fab1cffea9b6fd2f36bfb46e182fd77'
> md5('23')
'37693cfc748049e45d87b8c7d8b9aacd'

Python

>>> hash(23)
23
>>> hash('23')
6400038450057767

and R

> library(hashFunction)
> cityhash.64('23')
[1] 1301089509  153739053
> cityhash.64(as.integer(23))
[1]  1257865039 -2072067122

Moreover it breaks this test.

Is this behaviour intended or a bug?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions