--- /dev/null
+package org.simantics.graph.store;\r
+\r
+import gnu.trove.list.array.TIntArrayList;\r
+import gnu.trove.map.hash.TIntIntHashMap;\r
+import gnu.trove.map.hash.TIntObjectHashMap;\r
+import gnu.trove.map.hash.TObjectIntHashMap;\r
+import gnu.trove.procedure.TIntObjectProcedure;\r
+import gnu.trove.procedure.TIntProcedure;\r
+import gnu.trove.procedure.TObjectIntProcedure;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
+public class IndexMappingUtils {\r
+ \r
+ public static <T> TIntObjectHashMap<T> map(final TIntIntHashMap map, TIntObjectHashMap<T> target,\r
+ final TIntHashSet collisions) {\r
+ final TIntObjectHashMap<T> newTarget = new TIntObjectHashMap<T>();\r
+ target.forEachEntry(new TIntObjectProcedure<T>() {\r
+ @Override\r
+ public boolean execute(int a, T b) {\r
+ if(map.contains(a))\r
+ a = map.get(a);\r
+ if(newTarget.put(a, b) != null)\r
+ collisions.add(a);\r
+ return true;\r
+ }\r
+ });\r
+ return newTarget;\r
+ }\r
+ \r
+ public static void map(TIntIntHashMap map, TIntArrayList target) {\r
+ int size = target.size();\r
+ for(int i=0;i<size;++i) {\r
+ int id = target.getQuick(i);\r
+ if(map.contains(id))\r
+ target.setQuick(i, map.get(id));\r
+ }\r
+ } \r
+ \r
+ public static <T> void map(final TIntIntHashMap map, \r
+ final TObjectIntHashMap<T> target) {\r
+ target.forEachEntry(new TObjectIntProcedure<T>() {\r
+ @Override\r
+ public boolean execute(T a, int b) {\r
+ if(map.containsKey(b))\r
+ target.put(a, map.get(b));\r
+ return true;\r
+ }\r
+ });\r
+ }\r
+ \r
+ public static TIntHashSet map(final TIntIntHashMap map, TIntHashSet target) {\r
+ final TIntHashSet newTarget = new TIntHashSet();\r
+ target.forEach(new TIntProcedure() {\r
+ @Override\r
+ public boolean execute(int a) {\r
+ if(map.contains(a))\r
+ a = map.get(a);\r
+ newTarget.add(a);\r
+ return true;\r
+ }\r
+ });\r
+ return newTarget;\r
+ }\r
+\r
+ public static void map(TIntIntHashMap map, int[] target) {\r
+ for(int i=0;i<target.length;++i) {\r
+ int temp = target[i];\r
+ if(map.containsKey(temp))\r
+ target[i] = map.get(temp);\r
+ }\r
+ } \r
+\r
+}\r