]> gerrit.simantics Code Review - simantics/platform.git/blob
7b647806d87947ee25ee01a01152a90da44d18f2
[simantics/platform.git] /
1 package org.simantics.graph.compiler.internal.procedures;
2
3 import gnu.trove.map.hash.TIntIntHashMap;
4
5 import org.simantics.graph.store.GraphStore;
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 }