@@ -7,7 +7,7 @@ import java.util.*
7
7
private object Solution1 {
8
8
class AdvancedLRUCache (private val capacity : Int ) {
9
9
private val map: MutableMap <String , CacheItem > = mutableMapOf ()
10
- private val pq : PriorityQueue <CacheItem > = PriorityQueue ()
10
+ private val priorityQueue : PriorityQueue <CacheItem > = PriorityQueue ()
11
11
12
12
fun put (key : String , value : Int , priority : Int , expiryTime : Long ) {
13
13
if (map.containsKey(key)) {
@@ -20,7 +20,7 @@ private object Solution1 {
20
20
21
21
val item = CacheItem (key, value, priority, expiryTime)
22
22
map[key] = item
23
- pq .add(item)
23
+ priorityQueue .add(item)
24
24
}
25
25
26
26
fun get (key : String ): Int? {
@@ -44,16 +44,16 @@ private object Solution1 {
44
44
}
45
45
46
46
private fun clearCache () {
47
- while (pq .isNotEmpty() && pq .peek().expiryTime < getSystemTimeForExpiry()) {
48
- val item = pq .poll()
47
+ while (priorityQueue .isNotEmpty() && priorityQueue .peek().expiryTime < getSystemTimeForExpiry()) {
48
+ val item = priorityQueue .poll()
49
49
50
50
if (map.containsKey(item.key) && map[item.key] == item) {
51
51
map.remove(item.key)
52
52
}
53
53
}
54
54
55
- if (pq .isEmpty()) return
56
- val item = pq .poll()
55
+ if (priorityQueue .isEmpty()) return
56
+ val item = priorityQueue .poll()
57
57
if (map.containsKey(item.key) && map[item.key] == item) {
58
58
map.remove(item.key)
59
59
}
0 commit comments