Skip to content

Commit eba0492

Browse files
committed
💬 update LinkedHashMap
1 parent 6789bd2 commit eba0492

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

MD/collection/LinkedHashMap.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@
198198
}
199199

200200

201-
void addEntry(int hash, K key, V value, int bucketIndex) {
201+
//调用了 HashMap 的实现,并判断是否需要删除最少使用的 Entry(默认不删除)
202+
void addEntry(int hash, K key, V value, int bucketIndex) {
202203
super.addEntry(hash, key, value, bucketIndex);
203204

204205
// Remove eldest entry if instructed
@@ -207,6 +208,15 @@
207208
removeEntryForKey(eldest.key);
208209
}
209210
}
211+
212+
void createEntry(int hash, K key, V value, int bucketIndex) {
213+
HashMap.Entry<K,V> old = table[bucketIndex];
214+
Entry<K,V> e = new Entry<>(hash, key, value, old);
215+
//就多了这一步,将新增的 Entry 加入到 header 双向链表中
216+
table[bucketIndex] = e;
217+
e.addBefore(header);
218+
size++;
219+
}
210220
```
211221

212222

0 commit comments

Comments
 (0)