MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / inc

Method inc

src/class035/Code07_AllO1.java:51–76  ·  view source on GitHub ↗
(String key)

Source from the content-addressed store, hash-verified

49 }
50
51 public void inc(String key) {
52 if (!map.containsKey(key)) {
53 if (head.next.cnt == 1) {
54 map.put(key, head.next);
55 head.next.set.add(key);
56 } else {
57 Bucket newBucket = new Bucket(key, 1);
58 map.put(key, newBucket);
59 insert(head, newBucket);
60 }
61 } else {
62 Bucket bucket = map.get(key);
63 if (bucket.next.cnt == bucket.cnt + 1) {
64 map.put(key, bucket.next);
65 bucket.next.set.add(key);
66 } else {
67 Bucket newBucket = new Bucket(key, bucket.cnt + 1);
68 map.put(key, newBucket);
69 insert(bucket, newBucket);
70 }
71 bucket.set.remove(key);
72 if (bucket.set.isEmpty()) {
73 remove(bucket);
74 }
75 }
76 }
77
78 public void dec(String key) {
79 Bucket bucket = map.get(key);

Callers

nothing calls this directly

Calls 6

insertMethod · 0.95
removeMethod · 0.95
putMethod · 0.45
addMethod · 0.45
getMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected