K - 键的类型(通常是字串)V - 值的类型public class LruHashMap<K,V> extends Object implements Iterable<KvPair<K,V>>, GcCleanable
| 限定符和类型 | 类和说明 |
|---|---|
protected static class |
LruHashMap.Node<K,V>
hash表项
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected static org.slf4j.Logger |
_Logger |
protected int |
m_Height
链表高度
|
protected float |
m_LoadFactor
扩容因子
|
protected LruHashMap.Node<K,V> |
m_LruHead
LRU链表头
|
protected LruHashMap.Node<K,V> |
m_LruTail
LRU链表尾
|
protected int |
m_MaxCapacity
限制最大容量
|
protected int |
m_ModCount
变化计数
|
protected int |
m_Size
项数
|
protected LruHashMap.Node<K,V>[] |
m_Table
hash表
|
protected int |
m_Threshold
扩容表的阀值
|
POLICY_CRITICAL, POLICY_IDLE, POLICY_LOW, POLICY_MAINTAIN, POLICY_MASK, POLICY_OPTIMIZE| 构造器和说明 |
|---|
LruHashMap() |
LruHashMap(int initialCapacity) |
LruHashMap(int initialCapacity,
float loadFactor) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
afterNodeAccess(LruHashMap.Node<K,V> p)
节点被访问
|
protected void |
afterNodeInsertion(LruHashMap.Node<K,V> p)
新插入节点
|
protected void |
afterNodeRemoval(LruHashMap.Node<K,V> p)
节点被删除
|
protected void |
afterNodeUpdate(LruHashMap.Node<K,V> p)
节点被更新
|
void |
clear() |
protected void |
fixLru()
尝试修复LRU
|
V |
get(Object key) |
int |
getMaxCapacity() |
protected LruHashMap.Node<K,V> |
getNode(int hash,
Object key) |
V |
getOrDefault(Object key,
V defaultValue) |
protected static int |
hash(Object key) |
protected void |
initLru()
重新初始化LRU
|
Iterator<KvPair<K,V>> |
iterator()
遍历所有项(不支持remove)
|
Iterator<KvPair<K,V>> |
lru()
遍历LRU(不支持remove)
|
protected Object |
lruLock() |
protected LruHashMap.Node<K,V> |
newNode(int hash,
K key,
V value,
LruHashMap.Node<K,V> next) |
void |
onGcCleanup(int policy)
处理GC触发的清理事件,根据优先级以不同策略处理
|
protected LruHashMap.Node<K,V> |
openNode(int hash,
K key) |
protected void |
pinch()
压紧下hash表
|
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
protected void |
putLru(LruHashMap.Node<K,V> node)
更新到LRU链表首
|
protected void |
rebuild(LruHashMap.Node<K,V>[] oldTab,
int oldCap,
LruHashMap.Node<K,V>[] newTab,
int newCap) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
void |
removeAll() |
protected void |
removeLru(LruHashMap.Node<K,V> node)
由LRU表移除
|
protected LruHashMap.Node<K,V>[] |
resize() |
void |
setMaxCapacity(int maxCapacity)
限制最大项数
|
int |
size()
项数
|
protected Object |
tableLock() |
protected int |
tableSizeFor(int cap)
计算扩展的阀值
|
String |
toString() |
int |
trim(int expect)
按LRU表移除N项
|
protected static final org.slf4j.Logger _Logger
protected LruHashMap.Node<K,V>[] m_Table
protected volatile int m_Size
protected volatile int m_ModCount
protected int m_Threshold
protected final float m_LoadFactor
protected int m_MaxCapacity
protected final LruHashMap.Node<K,V> m_LruHead
protected final LruHashMap.Node<K,V> m_LruTail
protected int m_Height
public LruHashMap(int initialCapacity,
float loadFactor)
public LruHashMap(int initialCapacity)
public LruHashMap()
public int getMaxCapacity()
public void setMaxCapacity(int maxCapacity)
maxCapacity - 最大项数,若=0为MAXIMUM_CAPACITYpublic int size()
public void removeAll()
public void clear()
protected void initLru()
protected void fixLru()
protected void pinch()
public void onGcCleanup(int policy)
GcCleanableonGcCleanup 在接口中 GcCleanablepolicy - POLICY_xxxpublic int trim(int expect)
expect - 期望移除的项数protected Object tableLock()
protected Object lruLock()
protected LruHashMap.Node<K,V> getNode(int hash, Object key)
protected LruHashMap.Node<K,V> openNode(int hash, K key)
protected LruHashMap.Node<K,V>[] resize()
protected void rebuild(LruHashMap.Node<K,V>[] oldTab, int oldCap, LruHashMap.Node<K,V>[] newTab, int newCap)
protected void putLru(LruHashMap.Node<K,V> node)
node - 要更新的节点protected void removeLru(LruHashMap.Node<K,V> node)
node - 要由LRU移除的节点protected LruHashMap.Node<K,V> newNode(int hash, K key, V value, LruHashMap.Node<K,V> next)
protected void afterNodeAccess(LruHashMap.Node<K,V> p)
p - protected void afterNodeUpdate(LruHashMap.Node<K,V> p)
p - protected void afterNodeInsertion(LruHashMap.Node<K,V> p)
protected void afterNodeRemoval(LruHashMap.Node<K,V> p)
p - protected final int tableSizeFor(int cap)
cap - 表容量protected static final int hash(Object key)
Copyright © 2020. All rights reserved.