We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6789bd2 commit eba0492Copy full SHA for eba0492
1 file changed
MD/collection/LinkedHashMap.md
@@ -198,7 +198,8 @@
198
}
199
200
201
- void addEntry(int hash, K key, V value, int bucketIndex) {
+ //调用了 HashMap 的实现,并判断是否需要删除最少使用的 Entry(默认不删除)
202
+ void addEntry(int hash, K key, V value, int bucketIndex) {
203
super.addEntry(hash, key, value, bucketIndex);
204
205
// Remove eldest entry if instructed
@@ -207,6 +208,15 @@
207
208
removeEntryForKey(eldest.key);
209
210
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
+ }
220
```
221
222
0 commit comments