Skip to content

Commit d93cb04

Browse files
committed
Clean up
1 parent 3d362c2 commit d93cb04

File tree

1 file changed

+6
-6
lines changed
  • src/test/kotlin/com/igorwojda/cache/advancedlru

1 file changed

+6
-6
lines changed

src/test/kotlin/com/igorwojda/cache/advancedlru/Solution.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.util.*
77
private object Solution1 {
88
class AdvancedLRUCache(private val capacity: Int) {
99
private val map: MutableMap<String, CacheItem> = mutableMapOf()
10-
private val pq: PriorityQueue<CacheItem> = PriorityQueue()
10+
private val priorityQueue: PriorityQueue<CacheItem> = PriorityQueue()
1111

1212
fun put(key: String, value: Int, priority: Int, expiryTime: Long) {
1313
if (map.containsKey(key)) {
@@ -20,7 +20,7 @@ private object Solution1 {
2020

2121
val item = CacheItem(key, value, priority, expiryTime)
2222
map[key] = item
23-
pq.add(item)
23+
priorityQueue.add(item)
2424
}
2525

2626
fun get(key: String): Int? {
@@ -44,16 +44,16 @@ private object Solution1 {
4444
}
4545

4646
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()
4949

5050
if (map.containsKey(item.key) && map[item.key] == item) {
5151
map.remove(item.key)
5252
}
5353
}
5454

55-
if (pq.isEmpty()) return
56-
val item = pq.poll()
55+
if (priorityQueue.isEmpty()) return
56+
val item = priorityQueue.poll()
5757
if (map.containsKey(item.key) && map[item.key] == item) {
5858
map.remove(item.key)
5959
}

0 commit comments

Comments
 (0)