--- /dev/null
+package org.simantics.graph.compiler.internal.procedures;\r
+\r
+import gnu.trove.map.hash.TIntIntHashMap;\r
+\r
+import org.simantics.graph.store.GraphStore;\r
+\r
+public class Compactify implements Runnable {\r
+ GraphStore store;\r
+\r
+ public Compactify(GraphStore store) {\r
+ this.store = store;\r
+ }\r
+\r
+ @Override\r
+ public void run() {\r
+ // Mark all used resources\r
+ int resourceCount = store.identities.getResourceCount();\r
+ final boolean[] temp = new boolean[resourceCount];\r
+ store.collectReferences(temp);\r
+ \r
+ // Create a map\r
+ int newResourceCount = 0;\r
+ TIntIntHashMap map = new TIntIntHashMap(resourceCount);\r
+ for(int i=0;i<resourceCount;++i)\r
+ if(temp[i])\r
+ map.put(i, newResourceCount++);\r
+ if(newResourceCount < resourceCount) {\r
+ store.map(map);\r
+ store.identities.setResourceCount(newResourceCount);\r
+ }\r
+ }\r
+}\r