Given a $M\times M\times M$ 3D cube grid $C$, how can I map the 3D grid-coordinates to 1D coordinates such that every cell's nearest neighbors can be represented by a continuous range of corresponding 1D values?
One of the 3D-to-1D mappings could be Z-indexing, but I don't know how to access the neighbors in the way I described above.
Why do I need this: I'm writing an OpenCL kernel function, that processes particles. In each cell of the grid $C$ can be arbitrary (non-negative :) number of particles. The particles are stored in memory sorted by their cell's id given by the 1D coordinates. And to get the best GPU performance when reading neighbors, I need the neighboring particles to be close in memory (i.e. the 1D coordinates of a grid cells that are close to each other in space are also close).
If you want more of the context, you can see my questions at different SE sites: