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