K - key 泛型V - value 泛型public class MyHashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>
HashMapAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| 构造器和说明 |
|---|
MyHashMap() |
MyHashMap(int capacity)
初始化 hash map
|
MyHashMap(int capacity,
boolean debugMode)
初始化 hash map
|
| 限定符和类型 | 方法和说明 |
|---|---|
Set<Map.Entry<K,V>> |
entrySet()
遍历构建
当然比较好的做法是实时更新一个内部变量
|
V |
put(K key,
V value)
存储一个值
|
void |
putAll(Map<? extends K,? extends V> m)
批量添加,为了避免多次 rehash 可以首先扩容完成后,在进行相关元素的存储。
|
V |
remove(Object key)
删除一个元素
|
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, size, toString, valuesclear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, valuespublic MyHashMap()
public MyHashMap(int capacity)
capacity - 初始化容量public MyHashMap(int capacity,
boolean debugMode)
capacity - 初始化容量debugMode - 是否开启 debug 模式Copyright © 2020. All rights reserved.