From the link below, I know Java uses (hash & 0x7FFFFFFF) % tab.length to decide which slot of an array to put the {key, value} in.
My question is why Java first does hash & 0x7FFFFFFF? Is there any particular purpose?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
-1 % 10 == -1which you certainly don’t want for indexing into an array. Forcing the sign bit to 0 avoids this problem.