Function gamer::Vect2Index

Function Documentation

std::size_t gamer::Vect2Index(const std::size_t i, const std::size_t j, const std::size_t k, const Vector3szt &dim)

Convert 3D array indices to the index of a flat array.

As a convention use the following loop structure to optimize cache efficiency:

for (int k;...; k++){
  for (int j;...; j++){
    for (int i;...; i++){
In short, index i should occupy the inner most scope followed by j then k.


Index of flat array corresponding to indices in 3D array.

  • [in] i: Value of the first index

  • [in] j: Value of the second index

  • [in] k: Value of the third index

  • [in] dim: Dimensions of the 3D array