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