Here you can find the source of transpose(int[][][] as, int A, int[][][] ast)
Parameter | Description |
---|---|
as | a parameter |
public static void transpose(int[][][] as, int A, int[][][] ast)
//package com.java2s; //License from project: Common Public License import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class Main { /**/*w w w . j a v a 2s. c o m*/ * create transpose of sparse matrix * * @param as * @param [out] ast transpose */ public static void transpose(int[][][] as, int A, int[][][] ast) { int M = as[0].length; Map<Integer, Integer>[] x = new Map[A]; for (int m = 0; m < M; m++) { for (int n = 0; n < as[0][m].length; n++) { int ii = as[0][m][n]; if (x[ii] == null) { x[ii] = new HashMap<Integer, Integer>(); } x[ii].put(m, as[1][m][n]); } } map2sparse(x, ast); } /** * create a sparse array from the map * * @param x * @param [out] xs */ public static void map2sparse(Map<Integer, Integer>[] x, int[][][] xs) { // now fill the sparse array for (int i = 0; i < x.length; i++) { if (x[i] != null) { xs[0][i] = new int[x[i].size()]; xs[1][i] = new int[x[i].size()]; int j = 0; for (Entry<Integer, Integer> e : x[i].entrySet()) { xs[0][i][j] = e.getKey(); xs[1][i][j] = e.getValue(); j++; } } else { xs[0][i] = new int[0]; } } } }