K - key 泛型V - value 泛型public class MyProgressiveReHashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>
HashMapAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| 构造器和说明 |
|---|
MyProgressiveReHashMap() |
MyProgressiveReHashMap(int capacity)
初始化 hash map
|
MyProgressiveReHashMap(int capacity,
boolean debugMode)
初始化 hash map
|
| 限定符和类型 | 方法和说明 |
|---|---|
Set<Map.Entry<K,V>> |
entrySet()
遍历构建
当然比较好的做法是实时更新一个内部变量
|
V |
get(Object key)
查询方法
(1)如果处于渐进式 rehash 状态,额外执行一次 rehashToNew()
(2)判断 table 中是否存在元素
(3)判断 rehashTable 中是否存在元素
|
V |
put(K key,
V value)
put 一个值
(1)如果不处于 rehash 阶段
1.1 判断是否为 table 更新,如果是,则进行更新
1.2 如果不是更新,则进行插入
插入的时候可能触发 rehash
(2)如果处于 rehash 阶段
2.0 执行一次渐进式 rehash 的动作
2.1 判断是否为更新,需要遍历 table 和 rehashTable
如果是,执行更新
2.2 如果不是,则执行插入
插入到 rehashTable 中
|
clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, remove, size, toString, valuesclear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuespublic MyProgressiveReHashMap()
public MyProgressiveReHashMap(int capacity)
capacity - 初始化容量public MyProgressiveReHashMap(int capacity,
boolean debugMode)
capacity - 初始化容量debugMode - 是否开启 debug 模式public V get(Object key)
public V put(K key, V value)
Copyright © 2020. All rights reserved.