]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/Compactify.java
Removed org.simantics.ltk[.antlr] bundles, exact import for antlr
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / procedures / Compactify.java
1 package org.simantics.graph.compiler.internal.procedures;
2
3 import org.simantics.graph.store.GraphStore;
4
5 import gnu.trove.map.hash.TIntIntHashMap;
6
7 public class Compactify implements Runnable {
8         GraphStore store;
9
10         public Compactify(GraphStore store) {
11                 this.store = store;
12         }
13
14         @Override
15         public void run() {
16                 // Mark all used resources
17                 int resourceCount = store.identities.getResourceCount();
18                 final boolean[] temp = new boolean[resourceCount];
19                 store.collectReferences(temp);
20                 
21                 // Create a map
22                 int newResourceCount = 0;
23                 TIntIntHashMap map = new TIntIntHashMap(resourceCount);
24                 for(int i=0;i<resourceCount;++i)
25                         if(temp[i])
26                                 map.put(i, newResourceCount++);
27                 if(newResourceCount < resourceCount) {
28                         store.map(map);
29                         store.identities.setResourceCount(newResourceCount);
30                 }
31         }
32 }