If we have a 3x3x3 array of objects, which contain two members: a boolean, and an integer; can anyone suggest an efficient way of marking this array in to contiguous chunks, based on the boolean value.
For example, if we picture it as a Rubix cube, and a middle slice was missing (everything on 1,x,x == false), could we mark the two outer slices as separate groups, by way of a unique group identifier on the int member.

The same needs to apply if the "slice" goes through 90 degrees, leaving an L shape and a strip.

Could it be done with very large 3D arrays using recursion? Could it be threaded.

I've hit the ground typing a few times so far but have ended up in a few dead ends and stack overflows.

Very grateful for any help, thanks.