1 package net.obsearch.utils;
2
3 import hep.aida.bin.StaticBin1D;
4
5 import java.util.HashMap;
6 import java.util.HashSet;
7 import java.util.Set;
8 import java.util.Map.Entry;
9
10 import net.obsearch.index.utils.IntegerHolder;
11
12 public class MultiSet<O> {
13
14 private HashMap<O, IntegerHolder> set;
15
16 public MultiSet(int count){
17 set = new HashMap<O, IntegerHolder>(count);
18 }
19
20
21
22
23
24 public void add(O object){
25 IntegerHolder h = set.get(object);
26 if(h == null){
27 h = new IntegerHolder(0);
28 set.put(object, h);
29 }
30 h.inc();
31 }
32
33
34
35
36
37
38 public int cardinality(O object){
39 int res = 0;
40 IntegerHolder h = set.get(object);
41 if(h != null){
42 res = h.getValue();
43 }
44 return res;
45 }
46
47 public boolean containsKey(Object key) {
48 return set.containsKey(key);
49 }
50
51 public Set<Entry<O, IntegerHolder>> entrySet() {
52 return set.entrySet();
53 }
54
55 public boolean isEmpty() {
56 return set.isEmpty();
57 }
58
59 public Set<O> keySet() {
60 return set.keySet();
61 }
62
63
64
65
66
67 public StaticBin1D getDistribution(){
68 StaticBin1D res = new StaticBin1D();
69
70 for(Entry<O, IntegerHolder> e : entrySet()){
71 res.add(e.getValue().getValue());
72 }
73 return res;
74 }
75
76 }