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