title: HashMap implementation in Java. How does the bucket index calculation work?
body: <p>I am looking at the implementation of <code>HashMap</code> in Java and am stuck at one point.<BR>
  How is the <code>indexFor</code> function calculated?</p>
  
  <pre><code>static int indexFor(int h, int length) {
     return h &amp; (length-1);
  }
  </code></pre>
  
  <p>Thanks</p>