File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
src/main/java/com/crossoverjie/actual Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .crossoverjie .actual ;
2+
3+ import com .sun .scenario .effect .impl .prism .PrImage ;
4+
5+ import java .util .HashMap ;
6+ import java .util .Map ;
7+ import java .util .concurrent .LinkedBlockingQueue ;
8+
9+ /**
10+ * Function:
11+ *
12+ * @author crossoverJie
13+ * Date: 03/04/2018 00:08
14+ * @since JDK 1.8
15+ */
16+ public class LRUMap <K , V > {
17+ private final Map <K , V > cacheMap = new HashMap <>();
18+
19+ private int queueSize ;
20+
21+ private int nodeCount ;
22+
23+
24+ private Node <K ,V > header ;
25+ private Node <K ,V > tailer ;
26+
27+
28+ public void put (K key , V value ) {
29+ cacheMap .put (key , value );
30+
31+
32+ }
33+
34+ private void addNode (K key ,V value ){
35+ //容量满了删除最后一个
36+ if (queueSize == nodeCount ){
37+ tailer .next .tail = null ;
38+ tailer .next = null ;
39+ nodeCount -- ;
40+ }else {
41+ Node node = new Node (key ,value ) ;
42+
43+ }
44+
45+
46+ }
47+
48+
49+ private class Node <K ,V > {
50+ private K key ;
51+ private V value ;
52+ Node <K ,V > tail ;
53+ Node <K ,V > next ;
54+
55+ public Node (K key , V value ) {
56+ this .key = key ;
57+ this .value = value ;
58+ }
59+
60+ public K getKey () {
61+ return key ;
62+ }
63+
64+ public void setKey (K key ) {
65+ this .key = key ;
66+ }
67+
68+ public V getValue () {
69+ return value ;
70+ }
71+
72+ public void setValue (V value ) {
73+ this .value = value ;
74+ }
75+
76+ }
77+ }
You can’t perform that action at this time.
0 commit comments