Czy istnieją różne sposoby obliczania indeksu tabeli w HashMap

http://en.wikipedia.org/wiki/Hash_table

Patrzyłem na wiki i oto kroki, aby znaleźć indeks tabeli.

hash = hashfunc(key) // calculate hash value.
index = hash % array_size // calculate index value through modulus. 

Ale wydaje się, że sposób, w jaki jest wykonywany w Javie, jest zupełnie inny.

static int hash(int h) {
   h ^= (h >>> 20) ^ (h >>> 12);
   return h ^ (h >>> 7) ^ (h >>> 4);
}

static int indexFor(int h, int length) {
   return h & (length-1);
}

Metoda indexFor, która oblicza indeks tabeli, wydaje się być inna. Czy ktoś może dodać trochę światła na ten temat.

Aktualizacja:

Algorytm haszowania może się odpowiednio różnić, ale sposób, w jaki obliczamy indeks tabeli, powinien być nawet wtedy, gdy się nie mylę, ale widzę konflikt w tym, co robi wiki i jak działa java.

Przykładowy kod do przetestowania:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Test {

    public static void main(String args[]) {
        Map<String, String> m = new HashMap<String, String>();
        m.put("Shane", null);
        Iterator<String> itr = m.keySet().iterator();
        while (itr.hasNext()) {
            String key = itr.next();
            int hash = hash(key.hashCode());
            System.out.println("&&& used" + "table[" + (hash & 15) + "]=" + key);
            System.out.println("%%% used" + "table[" + (hash % 15) + "]=" + key);
        }
    }

    static int hash(int h) {
        h ^= (h >>> 20) ^ (h >>> 12);
        return h ^ (h >>> 7) ^ (h >>> 4);
    }   

}

Wydajność:

&&& usedtable[14]=Shane
%%% usedtable[8]=Shane

Uruchom powyższy program i zobaczysz, że indeks tabeli jest inny, gdy używam%, a indeks tabeli jest inny, gdy używam &.

questionAnswers(1)

yourAnswerToTheQuestion