1 package org.simantics.graph.store;
3 import gnu.trove.list.array.TIntArrayList;
4 import gnu.trove.map.hash.TIntIntHashMap;
5 import gnu.trove.map.hash.TIntObjectHashMap;
6 import gnu.trove.map.hash.TObjectIntHashMap;
7 import gnu.trove.procedure.TIntObjectProcedure;
8 import gnu.trove.procedure.TIntProcedure;
9 import gnu.trove.procedure.TObjectIntProcedure;
10 import gnu.trove.set.hash.TIntHashSet;
12 public class IndexMappingUtils {
14 public static <T> TIntObjectHashMap<T> map(final TIntIntHashMap map, TIntObjectHashMap<T> target,
15 final TIntHashSet collisions) {
16 final TIntObjectHashMap<T> newTarget = new TIntObjectHashMap<T>();
17 target.forEachEntry(new TIntObjectProcedure<T>() {
19 public boolean execute(int a, T b) {
22 if(newTarget.put(a, b) != null)
30 public static void map(TIntIntHashMap map, TIntArrayList target) {
31 int size = target.size();
32 for(int i=0;i<size;++i) {
33 int id = target.getQuick(i);
35 target.setQuick(i, map.get(id));
39 public static <T> void map(final TIntIntHashMap map,
40 final TObjectIntHashMap<T> target) {
41 target.forEachEntry(new TObjectIntProcedure<T>() {
43 public boolean execute(T a, int b) {
44 if(map.containsKey(b))
45 target.put(a, map.get(b));
51 public static TIntHashSet map(final TIntIntHashMap map, TIntHashSet target) {
52 final TIntHashSet newTarget = new TIntHashSet();
53 target.forEach(new TIntProcedure() {
55 public boolean execute(int a) {
65 public static void map(TIntIntHashMap map, int[] target) {
66 for(int i=0;i<target.length;++i) {
68 if(map.containsKey(temp))
69 target[i] = map.get(temp);