-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDescriptionIndex.java
More file actions
49 lines (44 loc) · 1021 Bytes
/
Copy pathDescriptionIndex.java
File metadata and controls
49 lines (44 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.HashMap;
import java.util.Set;
/**
* Collection of descriptions as a whole and count of items with the same
* descriptions
*
* @author G94
*/
public class DescriptionIndex {
HashMap<Set<Long>, Count> map; /*
* item counts indexed by description set
*/
final int MAGIC_SIZE = 8;
public DescriptionIndex() {
this.map = new HashMap<>();
}
void increment(Set<Long> descriptions) {
if (descriptions.size() >= MAGIC_SIZE) {
Count count = map.get(descriptions);
if (count == null)
map.put(descriptions, new Count(1));
else
count.value++;
}
}
void decrement(Set<Long> descriptions) {
if (descriptions.size() >= MAGIC_SIZE) {
Count count = map.get(descriptions);
if (count != null) {
if (count.value == 1)
map.remove(descriptions);
else
count.value--;
}
}
}
public int sameSame() {
int result = 0;
for (Count c : map.values())
if (c.value > 1)
result += c.value;
return result;
}
}