I need to iteratively generate the powerset of a large set, in a specific order. With iteratively I mean that with each call to getNext() (or similar) I get the next element of the powerset in the specific order. Precalculating and storing the entire powerset is not an option as it will be way too large; I am talking of the powerset of a 200-item set. Instead the specific order will allow me to optimize and skip ahead when "uninteresting" powerset elements turn up.
The specified order looks like this, for an ordered five item set with 1 representing to include the item in the powerset element (from left to right, top to bottom):
00000 10000 11000 11100 11110 11111
01000 10100 11010 11101
00100 10010 11001 11011
00010 10001 10110 10111
00001 01100 10101 01111
01010 10011
01001 01110
00110 01101
00101 01011
00011 00111
With "skip ahead" I mean that if I, for example, determine that 10010 does not fulfill some criterion, I know that none of the following powerset elements with two 1's will fulfill that criterion, so I can skip ahead to examine the powerset elements with three 1's.
I have implemented a partly working solution using shifting of parts of the powerset elements, but have so far not been able to figure out the logic for how to correctly handle all of it. Obviously, the sets with zero 1's and five 1's, and one 1 and four 1's are respective mirror images of each other, the interesting cases are the middle ones above, with two 1's and three 1's. Any help would be appreciated.