title: "Normalize" hash of Key in HashMap
body: <p>HashMap keeps its data in buckets as:</p>
  
  <pre><code>transient Node&lt;K,V&gt;[] table;
  </code></pre>
  
  <p>To put something in HashMap we need a hash() function which returns hash of Key in range from 0 to table.length(), right?</p>
  
  <p>Suppose, I have:</p>
  
  <pre><code>String s = "15315";
  
  // Just pasted internal operation. Is it supposed to calcule hash in table.length range?
  int h;
  int hmhc = (h = s.hashCode()) ^ (h &gt;&gt;&gt; 16);
  System.out.println("String native hashCode: "+s.hashCode() + ", HashMap hash: "+hmhc);
  </code></pre>
  
  <p>This returns the following:</p>
  
  <blockquote>
    <p>String native hashCode: 46882035, HashMap hash: 46882360</p>
  </blockquote>
  
  <p>We should have approximately 256 buckets (so hash of Key should be in range from 0 to 256), but internal hash in HashMap gives us 46882360. How to "normalize" this hash to our range? I just can't see it in the source code.</p>
  
  <p>I looked at this jdk ( put() starts from line 610): <a href="http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/HashMap.java" rel="nofollow noreferrer">http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/HashMap.java</a></p>