Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

集合-常见面试题下-HashMap 的长度为什么是 2 的幂次方这里逻辑不好 #2406

Closed
kiwiboom opened this issue May 29, 2024 · 1 comment
Labels
typo Correct typos

Comments

@kiwiboom
Copy link

建议改进
这个数组下标的计算方法是“ (n - 1) & hash”。(n 代表数组长度)。这也就解释了 HashMap 的长度为什么是 2 的幂次方。这个算法应该如何设计呢?
这句话多余,先介绍公式说就直接说能解释原因不合理。

@Snailclimb
Copy link
Owner

建议改进 这个数组下标的计算方法是“ (n - 1) & hash”。(n 代表数组长度)。这也就解释了 HashMap 的长度为什么是 2 的幂次方。这个算法应该如何设计呢? 这句话多余,先介绍公式说就直接说能解释原因不合理。

我都不知道哪一次抽风改成这样描述了,感谢指出!

@Snailclimb Snailclimb added the typo Correct typos label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typo Correct typos
Projects
None yet
Development

No branches or pull requests

2 participants