为什么哈希码被设计为返回int [英] Why was hashcode designed to return int

查看:215
本文介绍了为什么哈希码被设计为返回int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎哈希码总是返回一个整数.现在,由于IntMax,这似乎是一个限制因素.现在可以说这样的话,我们将永远不会有太多的对象,因为它会导致堆溢出等.但是,如果选择double而不是int,则可以在更大程度上保证哈希码对于不同的对象而言是唯一的?

It seems like a hashcode always returns an int. Now this appears to be a limiting factor due to IntMax. Now one can argue that such we would never have so many objects, as it would cause heap overflow etc. But if we chose double instead of int then we could guarantee with a much larger extent that hashcode wont be unique for distinct objects ?

推荐答案

哈希码不需要 是唯一的.这就是为什么它们是哈希码.用于哈希算法.不需要唯一的密钥.

Hashcodes don't need to be unique. That's why they are hashcodes. For use in hashing algorithms. Which don't need unique keys.

这篇关于为什么哈希码被设计为返回int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆