底层:数组+链表
transient volatile Node<K,V>[] table;
static class Node<K,V> implements Map.Entry<K,V> {
final int hash;
final K key;
volatile V val;
volatile Node<K,V> next;
if (key == null || value == null) throw new NullPointerException();
key value:不能为空;
HASH_BITS:
static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash
数组索引值(hash表 hash值)
static final int spread(int h) { return (h ^ (h >>> 16)) & HASH_BITS; }
h:key的hash code值
String中的hashcode()方法中的计算:
h = 31 * h + val[i];
val[i]:字符串中的每个字符
最大容量:
/**
* The largest possible table capacity. This value must be
* exactly 1<<30 to stay within Java array allocation and indexing
* bounds for power of two table sizes, and is further required
* because the top two bits of 32bit hash fields are used for
* control purposes.
*/
private static final int MAXIMUM_CAPACITY = 1 << 30;
暂停更新源码分析