Skip to content

Instantly share code, notes, and snippets.

@digital-synapse
Created August 27, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digital-synapse/1d5eaa9607df491e2cb5bc60526db62d to your computer and use it in GitHub Desktop.
Save digital-synapse/1d5eaa9607df491e2cb5bc60526db62d to your computer and use it in GitHub Desktop.
Fast 3D arrays in .Net
public class DataCube<T> {
public DataCube(int width, int height, int depth){
this.width = width;
this.height = height;
this.depth = depth;
size3d = width*height*depth;
size2d = width*height;
data = new T[size3d];
}
private T[] data;
private int width;
private int height;
private int depth;
private int size3d;
private int size2d;
public T this[int x, int y, int z]{
get { return data[index(x,y,z)]; }
set { data[index(x,y,z)] = value; }
}
private int index(int x, int y, int z){
return x + y * width + z * size2d;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment