5.1——Spread(hash) Source code analysis
/
* 1100 0011 1010 0101 0001 1100 0001 1110
* 0000 0000 0000 0000 1100 0011 1010 0101
* 1100 0011 1010 0101 1101 1111 1011 1011
* ---------------------------------------
* 1100 0011 1010 0101 1101 1111 1011 1011
* 0111 1111 1111 1111 1111 1111 1111 1111 ==HASH_BITS
* 0100 0011 1010 0101 1101 1111 1011 1011
*
*The current hash is moved right16bit or original hash&HASH_BITS Get the hash value of a positive number*Let high16bits are also involved in the operation*/
static final int spread(int h) {
return (h ^ (h >>> 16)) & HASH_BITS;
}
5.2——tabAt(tab, index) source code analysis
@SuppressWarnings("unchecked")
static final <K,V> Node<K,V> tabAt(Node<K,V>[] tab, int i) {
return (Node<K,V>)U.getObjectVolatile(tab, ((long)i << ASHIFT) + ABASE);
}
5.3———casTabAt(tab, index, c, v) source code analysis
static final <K,V> boolean casTabAt(Node<K,V>[] tab, int i,
Node<K,V> c, Node<K,V> v) {
return U.compareAndSwapObject(tab, ((long)i << ASHIFT) + ABASE, c, v);
}
5.4——setTabAt(tab, index, v) source code analysis
static final <K,V> void setTabAt(Node<K,V>[] tab, int i, Node<K,V> v) {
U.putObjectVolatile(tab, ((long)i << ASHIFT) + ABASE, v);
}
5.5——ResizeStamp(int n) Source code analysis
static final int resizeStamp(int n) {
return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1));
}
5.6——tableSizeFor(int c) source code analysis
private static final int tableSizeFor(int c) {
int n = c - 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;
}