Applies a supplemental hash function to a given hash code, which defends against poor quality hash functions. This is critical when the concurrent hash map uses power-of-two length hash tables, that otherwise encounter collisions for hash codes that do not differ in lower or upper bits. @param h ha
(int h)
| 1799 | * @param h hash code |
| 1800 | */ |
| 1801 | static int rehash(int h) { |
| 1802 | // Spread bits to regularize both segment and index locations, |
| 1803 | // using variant of single-word Wang/Jenkins hash. |
| 1804 | // TODO(kevinb): use Hashing/move this to Hashing? |
| 1805 | h += (h << 15) ^ 0xffffcd7d; |
| 1806 | h ^= (h >>> 10); |
| 1807 | h += (h << 3); |
| 1808 | h ^= (h >>> 6); |
| 1809 | h += (h << 2) + (h << 14); |
| 1810 | return h ^ (h >>> 16); |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * This method is a convenience for testing. Code should call {@link Segment#newEntry} directly. |