MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / put

Method put

Java/Leetcode/LeetcodeLruCache.java:24–33  ·  view source on GitHub ↗
(int key, int value)

Source from the content-addressed store, hash-verified

22 }
23
24 public void put(int key, int value) {
25 if(cache.containsKey(key)){
26 remove(cache.get(key));
27 }
28 if(cache.size() == capacity){
29 remove(tail.prev);
30 }
31 Node newNode = new Node(key,value);
32 insert(newNode);
33 }
34
35 private void remove(Node node){
36 cache.remove(node.key);

Callers 3

copyRandomListMethod · 0.45
bestHandMethod · 0.45
insertMethod · 0.45

Calls 4

removeMethod · 0.95
insertMethod · 0.95
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected