update hashmap
This commit is contained in:
@@ -2,3 +2,47 @@
|
||||
|
||||
java 中 hashmap的实现原理。
|
||||
|
||||
```
|
||||
public class HashMap<K,V> extends AbstractMap<K,V>
|
||||
implements Map<K,V>, Cloneable, Serializable {
|
||||
|
||||
static class Node<K,V> implements Map.Entry<K,V> {
|
||||
final int hash;
|
||||
final K key;
|
||||
V value;
|
||||
Node<K,V> next;
|
||||
...
|
||||
}
|
||||
|
||||
static final class TreeNode<K,V> extends LinkedHashMap.Entry<K,V> {
|
||||
TreeNode<K,V> parent; // red-black tree links
|
||||
TreeNode<K,V> left;
|
||||
TreeNode<K,V> right;
|
||||
TreeNode<K,V> prev; // needed to unlink next upon deletion
|
||||
boolean red;
|
||||
}
|
||||
|
||||
public V put(K key, V value) {
|
||||
return putVal(hash(key), key, value, false, true);
|
||||
}
|
||||
|
||||
public V get(Object key) {
|
||||
Node<K,V> e;
|
||||
return (e = getNode(hash(key), key)) == null ? null : e.value;
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### 扩容
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user