源码调试 --map篇--ConCurrentHashMap

 

底层:数组+链表

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;

暂停更新源码分析 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值