Skip to content
timaschew edited this page Jul 26, 2011 · 14 revisions

Welcome to the MDAAJ wiki!

What is MDDAJ?

Multidimensional Dynamic Array Api for Java. You can create dynamic multidimensional generic arrays at runtime.

How it works?

The There exist three implementations (extends from MDDABasic)

  • MDDAReal The array elements have an inner array and the inner array have an array inside it..., its nested for each dimension.
  • MDDACodeGen For this type, there will be generated a .class (byte code) at runtime with the specific dimensions.
  • MDDAPseudo This class provides a multidimensional access for the user, but the array is internally only one dimensional. This type gives best performance!

The MDDABasic function overview

// set the generic element at the indices (return type indicated if it was successfull)
boolean set(T value, int... indices)

// get the generic element at the indices
public T get(int... indices) 

// fill the whole array with the generic value
public boolean fill(T value) 

// convert the array into one dimensional array
public T[] flatten()

// print the array
public void print()

Getting Started

The standard way to create an array looks like this:

int[] a = new int[10];
double[][] b = new double[10][20];
String[][][][][] c = new String[10][20][5][8][15];
c[0][0][2][1][0] = "xyz";
String s = c[0][0][0][0][0];
for (int i=0; i<b.length; i++) {
  for (int j=0; j<b[i].length; i++) {
    b[i][j] = random.nextDouble();
  }
}

Creating the same array with MDDAJ:

MDDAPseudo<Integer> a = new MDDAPseudo<Integer>(10);
MDDAPseudo<Double> b = new MDDAPseudo<Double>(10,20);
MDDAPseudo<String> c = new MDDAPseudo<String>(10,20,5,8,15);
c.set("xyz", 0,0,2,1,0);
String s = c.get(0,0,0,0,0);
for (int i=0; i<b.dimensionSizeArray[0]; i++) {
  for (int j=0; j<dimensionSizeArray[1]; i++) {
    b.set(random.nextDouble(), i,j);
  }
}

NeighborInterface

The MDDAPSeudo implements this interface and provides the neighbors indices of an element for a grid topology. For example in a 2d space your array have the dimension 3x3, MDDAPseudo<Integer> a = new MDDAPseudo<Integer>(3,3); The numbers are the internal one dimensional indicies:

0 - 1 - 2
|   |   |
3 - 4 - 5
|   |   |
6 - 7 - 8

// internal one dim index < = = = = = => multi dim index
a.getMultiDimIndices(0) <= equivalent => a.get(0,0);
a.getMultiDimIndices(1) <= equivalent => a.get(0,1);
a.getMultiDimIndices(2) <= equivalent => a.get(0,2);
a.getMultiDimIndices(3) <= equivalent => a.get(1,0);
a.getMultiDimIndices(4) <= equivalent => a.get(1,1);

The neighbors indices will always used with the internal one dim index

int distance = 1; // reachable within one steps from the origin
Set<Integer> getNeighbors = a.getNeighborForAllDims(distance, 1,1)
// getNeighbors = {1,3,5,7}
Set<Integer> getNeighbors2 = a.getNeighborForAllDims(distance+1, 1,1)
// getNeighbors2 = {1,3,5,7,0,2,6,8}

You can also call a.getNeighborForDim(distance, 1, 1,1) for only the 2nd dimension, the result will be {3,5}

Clone this wiki locally