//指定位置设置值staticfinal<K,V>voidsetTabAt(Node<K,V>[] tab,int i, Node<K,V> v){
U.putObjectVolatile(tab,((long)i << ASHIFT)+ ABASE, v);}
5.5——resizeStamp(int n) 源码分析
/**
* Returns the stamp bits for resizing a table of size n.
* Must be negative when shifted left by RESIZE_STAMP_SHIFT.
* 扩容标识戳 一致才能参与扩容
* 16 -> 32
* numberOfLeadingZeros(16) => 1 0000 =>27 =>0000 0000 0001 1011
* | 16-1
* (1 << (RESIZE_STAMP_BITS - 1)) => 1000 0000 0000 0000 => 32768
* ---------------------------------------------------------------
* 0000 0000 0001 1011
* 1000 0000 0000 0000
* 1000 0000 0001 1011
*/staticfinalintresizeStamp(int n){return Integer.numberOfLeadingZeros(n)|(1<<(RESIZE_STAMP_BITS -1));}
5.6——tableSizeFor(int c) 源码分析
/**
* Returns a power of two table size for the given desired capacity.
* See Hackers Delight, sec 3.2
* 返回>=c的最小的2的次方数
* c=28
* n=27 => 0b 11011
* 11011 | 01101 => 11111
* 11111 | 00111 => 11111
* ....
* => 11111 + 1 =100000 = 32
*/privatestaticfinalinttableSizeFor(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;}