java 1 30,為什么Java HashMap 1的最大容量<30,而不是1< 31?

4

While it would be possible for a hash map to handle quantities of items between 2^30 and 2^31-1 without having to use larger integer types, writing code which works correctly even near the upper limits of a language's integer types is difficult. Further, in a language which treats integers as an abstract algebraic ring that "wraps" on overflow, rather than as numbers which should either yield numerically-correct results or throw exceptions when they cannot do so, it may be hard to ensure that there aren't any cases where overflows would cause invalid operations to go undetected.

雖然它可能為一個散列映射來處理大量的物品2 ^ 30至2 ^還有無需使用較大的整數類型,正確地編寫代碼工作甚至在一個語言的整數類型的上限是很困難的。進一步,把整數的語言作為一個抽象的代數環,“包裝”溢出,而不是數字應該產生numerically-correct的結果或拋出異常時,不能這樣做,它可能很難確保沒有任何溢出的情況下會導致無效的操作去未被發現。

Specifying an upper limit of 2^30 or even 2^29, and ensuring correct behavior on things no larger than that, is often much easier than trying to ensure correct behavior all the way up to 2^31-1. Absent a particular reason to squeeze out every last bit of range, it's generally better to use the simpler approach.

指定一個上限2 ^ 30甚至2 ^ 29,並確保正確的行為對事物沒有比,往往比努力更容易確保正確的行為一直到2 ^還有。如果沒有一個特別的理由來擠出最后的范圍,那么最好使用更簡單的方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值