@@ -84,8 +84,8 @@ private class Node {
84
84
private int capacity ;
85
85
private int count ;
86
86
private DoublyLinkedListPlusHashMapSolution .Node head ,tail ;
87
- private Map <Integer ,DoublyLinkedListPlusHashMapSolution .Node >map ;// ATTN: the value should be Node type! This is the whole point
88
- // of having a class called Node!
87
+ private Map <Integer ,DoublyLinkedListPlusHashMapSolution .Node >map ;
88
+ //ATTN: the value should be Node type! This is the whole point of having a class called Node!
89
89
90
90
public DoublyLinkedListPlusHashMapSolution (int capacity ) {
91
91
this .capacity =capacity ;
@@ -99,8 +99,8 @@ public DoublyLinkedListPlusHashMapSolution(int capacity) {
99
99
}
100
100
101
101
public int get (int key ) {
102
- DoublyLinkedListPlusHashMapSolution .Node node =map .get (key );// HashMap allows value to be null, this is superior than
103
- // HashTable!
102
+ DoublyLinkedListPlusHashMapSolution .Node node =map .get (key );
103
+ //HashMap allows value to be null, this is superior than HashTable!
104
104
if (node ==null ) {
105
105
return -1 ;
106
106
}else {
@@ -118,9 +118,9 @@ public void set(int key, int value) {
118
118
count ++;
119
119
120
120
if (count >capacity ) {
121
- // ATTN: It's tail.prev, not tail, because tail is always an invalid node, it
122
- // doesn't contain anything, it's always the tail.prev that is the last node in the
123
- // cache
121
+ /** ATTN: It's tail.prev, not tail, because tail is always an invalid node, it
122
+ doesn't contain anything, it's always the tail.prev that is the last node in the
123
+ cache*/
124
124
DoublyLinkedListPlusHashMapSolution .Node toDelete =tail .prev ;
125
125
map .remove (toDelete .key );
126
126
remove (toDelete );
@@ -134,10 +134,9 @@ public void set(int key, int value) {
134
134
}
135
135
136
136
private void update (DoublyLinkedListPlusHashMapSolution .Node node ) {
137
- // this simplifies the process, just do two operations, remove the old node first, and then
138
- // just add the node again
139
- // this will guarantee that this node will be at the latest position: the most recently used
140
- // position.
137
+ /** this simplifies the process, just do two operations, remove the old node first, and then
138
+ just add the node again this will guarantee that this node will be at the latest position:
139
+ the most recently used position.*/
141
140
remove (node );
142
141
add (node );
143
142
}
@@ -148,8 +147,8 @@ private void remove(DoublyLinkedListPlusHashMapSolution.Node node) {
148
147
next .prev =prev ;
149
148
}
150
149
151
- private void add (DoublyLinkedListPlusHashMapSolution .Node node ) {// ATTN: we'll always add the node into the first position:
152
- // head.next!!!!
150
+ private void add (DoublyLinkedListPlusHashMapSolution .Node node ) {
151
+ //ATTN: we'll always add the node into the first position: head.next!!!!
153
152
DoublyLinkedListPlusHashMapSolution .Node next =head .next ;
154
153
head .next =node ;
155
154
node .next =next ;