一般的に使用されますjava.util.HashMap
/**
* Returns index for hash code h.
*/
static int indexFor(int h, int length) {
return h & (length-1);
}
ここで、長さは底 2 です。
または Lucene ブルーム フィルター コード (org.apache.lucene.codecs.bloom.FuzzySet)
// Bloom sizes are always base 2 and so can be ANDed for a fast modulo
int pos = positiveHash & bloomSize;
たとえば 8 の場合、 と の差はゼロi % 8
ではないため、私には意味がありません!i & 8
scala> (0 to 20).map(i => (i & 8) - (i % 8))
res33: scala.collection.immutable.IndexedSeq[Int] = Vector(0, -1, -2, -3, -4, -5, -6, -7, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4)