Skip to content

Instantly share code, notes, and snippets.

@you-ssk
Created November 25, 2012 08:38
Show Gist options
  • Save you-ssk/4142858 to your computer and use it in GitHub Desktop.
Save you-ssk/4142858 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <memory.h>
#include <map>
void add(
int *buffer,
std::map<int,int>& plot,
int key,
int value)
{
int tmp = plot[key];
plot[key] = value;
buffer[value] = tmp;
}
int _tmain(int argc, _TCHAR* argv[])
{
int width = 100;
int height = 100;
int depth = 100;
int nbin = 10;
int buf_size = width*height*depth;
int *buffer = new int[buf_size];
memset(buffer, 0, buf_size*sizeof(int));
std::map<int,int> plot;
for (int z = 0; z < depth; z++){
for (int y = 0; y < height; y++){
for (int x = 0; x < width; x++){
int index = 1 + x + y*width + z*width*height;
int key = index % nbin;
add(buffer, plot, key, index);
//printf("%d = %2d(%2d,%2d,%2d)\n", key, index-1, x, y, z);
}
}
}
for (std::map<int,int>::iterator itr = plot.begin(); itr != plot.end(); itr++){
int key = itr->first;
int index = itr->second;
while (index != 0){
int z = (index-1)/(width*height);
int mod = (index-1)%(width*height);
int y = mod/height;
int x = mod%height;
//printf("%d = %2d(%2d,%2d,%2d)\n", key, index-1, x, y, z);
index = buffer[index];
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment