privateinttableSizeFor(int cap){ int n = cap - 1; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; }
publicvoidadd(Integer val){ int index; int bit;
index = hash1(val) & (size * 32 - 1); bit = index & ((1 << 5) - 1); index = index >> 5; arr[index] |= (1 << bit);
index = hash2(val) & (size * 32 - 1); bit = index & ((1 << 5) - 1); index = index >> 5; arr[index] |= (1 << bit); }
publicinthash1(Integer val){ int hash = val * 2017;//找了一个质数,下同 return hash; }
publicinthash2(Integer val){ int hash = val * 2027; return hash; }
publicbooleancontains(Integer val){ int index; int bit;
index = hash1(val) & (size * 32 - 1); bit = index & ((1 << 5) - 1); index = index >> 5; boolean hash1 = ((arr[index] & (1 << bit)) != 0);
index = hash2(val) & (size * 32 - 1); bit = index & ((1 << 5) - 1); index = index >> 5; boolean hash2 = ((arr[index] & (1 << bit)) != 0);