| 1 | package align2; |
| 2 | |
| 3 | public class Pointer implements Comparable<Pointer>{ |
| 4 | |
| 5 | public static Pointer[] loadMatrix(int[][] matrix){ |
| 6 | Pointer[] out=new Pointer[matrix.length]; |
| 7 | for(int i=0; i<out.length; i++){ |
| 8 | int len=(matrix[i]==null ? 0 : matrix[i].length); |
| 9 | out[i]=new Pointer(i, len); |
| 10 | } |
| 11 | return out; |
| 12 | } |
| 13 | |
| 14 | public static Pointer[] loadMatrix(int[][] matrix, Pointer[] out){ |
| 15 | assert(out!=null); |
| 16 | assert(out.length==matrix.length); |
| 17 | for(int i=0; i<out.length; i++){ |
| 18 | Pointer p=out[i]; |
| 19 | int len=(matrix[i]==null ? 0 : matrix[i].length); |
| 20 | p.key=i; |
| 21 | p.value=len; |
| 22 | } |
| 23 | return out; |
| 24 | } |
| 25 | |
| 26 | public Pointer(int key_, int value_){ |
| 27 | key=key_; |
| 28 | value=value_; |
| 29 | } |
| 30 | |
| 31 | @Override |
| 32 | public int compareTo(Pointer o) { |
| 33 | return value-o.value; |
| 34 | } |
| 35 | |
| 36 | public int key; |
| 37 | public int value; |
| 38 | } |