1 | package tuffy.infer.ds; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.HashMap; |
5 | /** |
6 | * A block of ground atoms. Exactly one atom in a block can be true. |
7 | */ |
8 | public class KeyBlock{ |
9 | |
10 | public HashMap<Integer, ArrayList<GAtom>> keyConstraints = new HashMap<Integer, ArrayList<GAtom>>(); |
11 | |
12 | public HashMap<GAtom, Integer> gatom2key = new HashMap<GAtom, Integer>(); |
13 | |
14 | public void pushGAtom(Integer key, GAtom gatom){ |
15 | |
16 | if(!keyConstraints.containsKey(key)){ |
17 | this.keyConstraints.put(key, new ArrayList<GAtom>()); |
18 | } |
19 | this.keyConstraints.get(key).add(gatom); |
20 | this.gatom2key.put(gatom, key); |
21 | } |
22 | |
23 | public boolean hasKey(GAtom gatom){ |
24 | return this.gatom2key.containsKey(gatom); |
25 | } |
26 | |
27 | public ArrayList<GAtom> getBlockMates(GAtom gatom){ |
28 | return this.keyConstraints.get(gatom2key.get(gatom)); |
29 | } |
30 | |
31 | } |