-
Notifications
You must be signed in to change notification settings - Fork 0
Home
timaschew edited this page Jul 13, 2011
·
14 revisions
Welcome to the MDAAJ wiki!
Multidimensional Dynamic Array Api for Java. You can create dynamic multidimensional generic arrays at runtime.
The There exist three implementations (extends from MDDABasic)
- MDDAReal The array ist not real multidimensional, its nested (nested dimension times)
- MDDACodeGen For this type, there will be generated a .class (byte code) at runtime with the specific dimension
- MDDAPseudo This class provides an multidimensional access for the user, but the array is internally only one dimensional
The MDDABasic function overview
// set the generic element at the indices (return type indicated if the 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()
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];
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);
The MDDAPSeudo implements this interface and provides the neighbors elements 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
int distance = 1;
Set<Integer> getNeighbors = a.getNeighborForAllDims(distance, 1,1) // indices (1,1) -> 4
// getNeighbors = {1,3,5,7}
Set<Integer> getNeighbors2 = a.getNeighborForAllDims(distance+1, 1,1) // indices (1,1) -> 4
// 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}