javastaticintindexFor(inth,intlength){//assertInteger.bitCount(length)==1:"lengthmustbeanon-zeropowerof2";returnh&(length-1);}這是hashmap源碼的一個(gè)函數(shù),作用是將hashcode對應(yīng)到hashmap數(shù)組里面的下標(biāo)。`h&(length-1)`是什么運(yùn)算呢?這樣能保證下標(biāo)是唯一的嗎?
求大神解讀一下這段源碼
陪伴而非守候
2019-04-10 20:47:46