package com.mollen.resource.map;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* IHashMap
*
* @author 阔皮大师.
* @created 2022-04-27 23:56
*/
public class IHashMap<K,V> {
// 初始化数组长度
static final int DEFAULT_INITIAL_CAPACITY = 1 << 4;
// 数组最大长度
static final int MAXIMUM_CAPACITY = 1 << 30;
// 链表转树阈值
static final int TREEIFY_THRESHOLD = 8;
// 扩容系数
static final float DEFAULT_LOAD_FACTOR = 0.75f;
// 树转链表阈值
static final int UNTREEIFY_THRESHOLD = 6;
// 树化最小容量
static final int MIN_TREEIFY_CAPACITY = 64;
// Hash表
transient Node<K,V>[] table;
// 上一次扩容之后的容量阈值
int threshold;
/**
* 定义Node【数组元素】
*/
static class Node<K,V> implements Map.Entry<K,V> {
final int hash;
final K key;
V value;
// 链表下一个节点,默认赋null,有新元素进来替换掉null
Node<K,V> next;
Node(int hash, K key, V value, Node<K,V> next) {
this.hash = hash;
this.key = key;
this.value = value;
this.next = next;
}
public final K getKey() {
return key;
}
public final V getValue() {
return value;
}
public final String toString() {
return key + "=" + value;
}
public final int hashCode() {
return Objects.hashCode(key) ^ Objects.hashCode(value);
}
public final V setValue(V newValue) {
V oldValue = value;
value = newValue;
return oldValue
HashMap putValue() 和 resize()方法 源码理解
于 2022-05-01 01:11:46 首次发布
本文详细介绍了IHashMap类的实现,包括初始化、扩容、插入操作等核心功能。IHashMap使用了链表和红黑树的数据结构解决哈希冲突,通过putVal方法处理元素插入,并在数组达到特定阈值时进行扩容。此外,还涉及到了树化和去树化的阈值设定。

最低0.47元/天 解锁文章
1034

被折叠的 条评论
为什么被折叠?



