For a Java project, I have 5 ENUM types that I need to use to index an 3-dimensional array of doubles, which define a particular property for each of several XYZ points in 3D rectilinear space. Would it be better to organize it like so:
double[][][][][][][][] arr =
new double[enum1Size][enum2Size][enum3Size][enum4Size][enum5Size]
[maxX+1][maxY+1][maxZ+1];
arr[enum1][enum2][enum3][enum4][enum5][x][y][z] = theDouble;
Or by using a simple array and indexing it using a hashCode of an object containing each of the enums:
class EnumIndex {
Enum1Type enum1;
Enum2Type enum2;
Enum3Type enum3;
Enum4Type enum4;
Enum5Type enum5;
public EnumIndex(Enum1Type enum1, Enum2Type enum2,
Enum3Type enum3, Enum4Type enum4, Enum5Type enum5) {
this.enum1 = enum1;
this.enum2 = enum2;
this.enum3 = enum3;
this.enum4 = enum4;
this.enum5 = enum5;
}
public int hashCode() {
// Eclipse-generated hashcode function
}
public static int maxHashCode() {
// generate maximum hashcode based on maximum ordinal of each enum
}
}
double[][][][] arr = new double[EnumIndex.maxHashcode+1][maxX+1][maxY+1][maxZ+1];
EnumIndex ei1 = new EnumIndex(enum1, enum2, enum3, enum4, enum5);
double[ei1][x][y][z] = theDouble;
- Enum1Type has 15 values.
- Enum2Type has 4 values.
- Enum3Type has 4 values.
- Enum4Type has 2 values.
Enum5Type has 2 values.
X ranges from 0-9
- Y ranges from 0-5
- Z ranges from 0-22
Therefore there are on the order of 1,324,800 doubles to be indexed.
I was going to use EnumMaps of EnumMaps, but that seemed to be overkill. Processing speed is a big concern on this project, so I'm trying to avoid iteration; forcing the runtime to use pointer arithmetic to get at the right memory locations.