In java, hashcode() method, returns integer instead of long. Is there any specific reason?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Using the hashCode is to have N buckets where the hashCode % N determines the bucket of elements, hopefully being 1 (no conflicting hashCodes).
For N, for the hash code, an int is entirely sufficient; indeed one needs to have most variety in the lower bits; having a long without using the higher bits (when N would be a power of 2), would be counter productive.
Speed of course is a requirement too: int being slightly better on the final CPU.
Well, one good reason is that the
hashCode
based data structures (HashSet
,HashMap
) use an array to store the bins, and arrays are limited toint
indices. You will gain nothing by along
hashCode()
if you must map it to anint
array index.