MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / inc

Method inc

AllOoneDataStructure.java:25–48  ·  view source on GitHub ↗
(String key)

Source from the content-addressed store, hash-verified

23 }
24
25 public void inc(String key) {
26 Node cur = head;
27 int newFreq = 1;
28 if(map.containsKey(key)){
29 cur = map.get(key);
30 newFreq = cur.freq + 1;
31 cur.keys.remove(key);
32 }
33 if(cur.next.freq == newFreq){
34 cur.next.keys.add(key);
35 }else{ // insert a node with newFreq
36 Node node = new Node(newFreq);
37 node.keys.add(key);
38 Node nextNode = cur.next;
39 node.next = nextNode;
40 nextNode.prev = node;
41 cur.next = node;
42 node.prev = cur;
43 }
44 map.put(key, cur.next);
45 if(cur.keys.size()==0 && cur!=head){
46 removeNode(cur);
47 }
48 }
49
50 public void dec(String key) {
51 Node cur = map.get(key);

Callers

nothing calls this directly

Calls 2

removeNodeMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected