]> gerrit.simantics Code Review - simantics/platform.git/blob
61658b1a855d1213f10347c865d350e1e79ff5dc
[simantics/platform.git] /
1 package org.simantics.graph.compiler.internal.procedures;
2
3 import gnu.trove.list.array.TIntArrayList;
4 import gnu.trove.map.hash.TIntIntHashMap;
5
6 import org.simantics.graph.query.Paths;
7 import org.simantics.graph.store.GraphStore;
8 import org.simantics.graph.store.IdentityStore;
9
10 public class MergeEqualResources implements Runnable {
11
12         GraphStore store;
13         Paths paths;
14                 
15         public MergeEqualResources(Paths paths, GraphStore store) {
16             this.paths = paths;
17                 this.store = store;
18         }
19
20         @Override
21         public void run() {
22                 IdentityStore identities = store.identities;
23                 if(identities.contains(paths.Equals)) {
24                         int equalsId = identities.pathToId(paths.Equals);
25                         identities.removeIdentity(equalsId);
26                         TIntArrayList rel = store.statements.extractRelation(equalsId);
27                         for(int i=0;i<rel.size();i+=2)
28                                 identities.unify(rel.get(i), rel.get(i+1));
29                 }
30                 
31                 TIntIntHashMap map = identities.extractUnifications();
32                 do {
33                         store.map(map);                 
34                         map = identities.extractUnifications();
35                 } while(!map.isEmpty());
36         }       
37
38 }