351 |
|
* based on the current thread's Thread.getId(). These hash codes |
352 |
|
* have more uniform distribution properties with respect to small |
353 |
|
* moduli (here 1-31) than do other simple hashing functions. |
354 |
< |
* To return an index between 0 and max, we use a cheap |
354 |
> |
* |
355 |
> |
* <p>To return an index between 0 and max, we use a cheap |
356 |
|
* approximation to a mod operation, that also corrects for bias |
357 |
< |
* due to non-power-of-2 remaindering (see {@link Random#nextInt}). |
358 |
< |
* Bits of the hashcode are masked with "nbits", the ceiling power |
359 |
< |
* of two of table size (looked up in a table packed into three |
360 |
< |
* ints). If too large, this is retried after rotating the hash by |
361 |
< |
* nbits bits, while forcing new top bit to 0, which guarantees |
362 |
< |
* eventual termination (although with a non-random-bias). This |
363 |
< |
* requires an average of less than 2 tries for all table sizes, |
364 |
< |
* and has a maximum 2% difference from perfectly uniform slot |
365 |
< |
* probabilities when applied to all possible hash codes for sizes |
366 |
< |
* less than 32. |
357 |
> |
* due to non-power-of-2 remaindering (see {@link |
358 |
> |
* java.util.Random#nextInt}). Bits of the hashcode are masked |
359 |
> |
* with "nbits", the ceiling power of two of table size (looked up |
360 |
> |
* in a table packed into three ints). If too large, this is |
361 |
> |
* retried after rotating the hash by nbits bits, while forcing new |
362 |
> |
* top bit to 0, which guarantees eventual termination (although |
363 |
> |
* with a non-random-bias). This requires an average of less than |
364 |
> |
* 2 tries for all table sizes, and has a maximum 2% difference |
365 |
> |
* from perfectly uniform slot probabilities when applied to all |
366 |
> |
* possible hash codes for sizes less than 32. |
367 |
|
* |
368 |
|
* @return a per-thread-random index, 0 <= index < max |
369 |
|
*/ |
384 |
|
/** |
385 |
|
* Creates a new slot at given index. Called only when the slot |
386 |
|
* appears to be null. Relies on double-check using builtin |
387 |
< |
* locks, since they rarely contend. This in turn relies on the |
387 |
> |
* locks, since they rarely contend. This in turn relies on the |
388 |
|
* arena array being declared volatile. |
389 |
|
* |
390 |
|
* @param index the index to add slot at |