stbcc 0.94

This commit is contained in:
Sean Barrett 2016-04-17 09:16:26 -07:00
parent 51393c0a7a
commit 25b1f563d1
2 changed files with 10 additions and 4 deletions

View File

@ -1,4 +1,4 @@
// stb_connected_components - v0.93 - public domain connected components on grids // stb_connected_components - v0.94 - public domain connected components on grids
// http://github.com/nothings/stb // http://github.com/nothings/stb
// //
// Finds connected components on 2D grids for testing reachability between // Finds connected components on 2D grids for testing reachability between
@ -32,8 +32,12 @@
// Making one square untraversable: 0.23 ms (average over 30,123 calls) // Making one square untraversable: 0.23 ms (average over 30,123 calls)
// Reachability query: 0.00001 ms (average over 4,000,000 calls) // Reachability query: 0.00001 ms (average over 4,000,000 calls)
// //
// On non-degenerate maps update time is O(N^0.5), but on degenerate maps like
// checkerboards or 50% random, update time is O(N^0.75) (~2ms on above machine).
//
// CHANGELOG // CHANGELOG
// //
// 0.94 (2016-04-17) Bugfix & optimize worst case (checkerboard & random)
// 0.93 (2016-04-16) Reduce memory by 10x for 1Kx1K map; small speedup // 0.93 (2016-04-16) Reduce memory by 10x for 1Kx1K map; small speedup
// 0.92 (2016-04-16) Compute sqrt(N) cluster size by default // 0.92 (2016-04-16) Compute sqrt(N) cluster size by default
// 0.91 (2016-04-15) Initial release // 0.91 (2016-04-15) Initial release
@ -980,7 +984,8 @@ static void stbcc__build_clumps_for_cluster(stbcc_grid *g, int cx, int cy)
assert(g->clump_for_node[y+j][x+i] <= STBCC__NULL_CLUMPID); assert(g->clump_for_node[y+j][x+i] <= STBCC__NULL_CLUMPID);
} }
// set the global label for all interior clumps since they can't have connections, so we don't have to do this on the global pass // set the global label for all interior clumps since they can't have connections,
// so we don't have to do this on the global pass (brings from O(N) to O(N^0.75))
for (i=(int) c->num_edge_clumps; i < (int) c->num_clumps; ++i) { for (i=(int) c->num_edge_clumps; i < (int) c->num_clumps; ++i) {
stbcc__global_clumpid gc; stbcc__global_clumpid gc;
gc.f.cluster_x = cx; gc.f.cluster_x = cx;

View File

@ -149,11 +149,12 @@ int main(int argc, char **argv)
for (i=0; i < w; ++i) for (i=0; i < w; ++i)
for (j=0; j < h; ++j) for (j=0; j < h; ++j)
map[j*w+i] = (((i+1) ^ (j+1)) >> 1) & 1 ? 255 : 0; //map[j*w+i] = (((i+1) ^ (j+1)) >> 1) & 1 ? 255 : 0;
map[j*w+i] = stb_max(abs(i-w/2),abs(j-h/2)) & 1 ? 255 : 0;
//map[j*w+i] = (((i ^ j) >> 5) ^ (i ^ j)) & 1 ? 255 : 0; //map[j*w+i] = (((i ^ j) >> 5) ^ (i ^ j)) & 1 ? 255 : 0;
//map[j*w+i] = stb_rand() & 1 ? 255 : 0; //map[j*w+i] = stb_rand() & 1 ? 255 : 0;
#if 0 #if 1
for (i=0; i < 100000; ++i) for (i=0; i < 100000; ++i)
map[(stb_rand()%h)*w + stb_rand()%w] ^= 255; map[(stb_rand()%h)*w + stb_rand()%w] ^= 255;
#endif #endif