diff --git a/stb_connected_components.h b/stb_connected_components.h index 3cf9409..abe2d8e 100644 --- a/stb_connected_components.h +++ b/stb_connected_components.h @@ -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 // // 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) // 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 // +// 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.92 (2016-04-16) Compute sqrt(N) cluster size by default // 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); } - // 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) { stbcc__global_clumpid gc; gc.f.cluster_x = cx; diff --git a/tests/grid_reachability.c b/tests/grid_reachability.c index 93667d4..8314d00 100644 --- a/tests/grid_reachability.c +++ b/tests/grid_reachability.c @@ -149,11 +149,12 @@ int main(int argc, char **argv) for (i=0; i < w; ++i) 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] = stb_rand() & 1 ? 255 : 0; - #if 0 + #if 1 for (i=0; i < 100000; ++i) map[(stb_rand()%h)*w + stb_rand()%w] ^= 255; #endif