| 23 | } |
| 24 | |
| 25 | fun get(key: Int): Int { |
| 26 | if (key !in hashmap) { |
| 27 | return -1 |
| 28 | } |
| 29 | // To make this key the most recently used, remove its node and |
| 30 | // re-add it to the tail of the linked list. |
| 31 | val node = hashmap[key]!! |
| 32 | removeNode(node) |
| 33 | addToTail(node) |
| 34 | return node.value |
| 35 | } |
| 36 | |
| 37 | fun put(key: Int, value: Int) { |
| 38 | // If a node with this key already exists, remove it from the |