
#include "bits/bit-sl-gray.h"

#include "bits/print-bin.h"

#include "fxttypes.h"
#include "fxtio.h"
#include "bits/bitsperlong.h"

#include "nextarg.h"


//% Binary words in a minimal-change order
//% related so subset-lex order ("SL-Gray" order).

// Cf. bits/bitlex-demo.cc for subset-lex order.
// Cf. comb/binary-sl-gray-demo.cc for generation in an array.

//#define TIMING // uncomment to disable printing

int
main(int argc, char **argv)
{
    ulong n = 6;
    NXARG(n, "n-bit binary words");


    bit_sl_gray G(n);
    ulong ct = 0;

#ifdef TIMING
    do  { ++ct; }  while ( G.next() );

#else
    ulong xo = 0;
    do
    {
        cout  << setw(4) << ct << ":";
        ++ct;
        ulong x = G.data();
        print_bin("    ", x, n);  // words of the Gray code
        print_bin("    ", x^xo, n);  // delta sequence
        xo = G.data();
//        print_bin("    ", G.tr_, n);

        cout << endl;
    }
    while ( G.next() );
#endif
    cout << " ct=" << ct << endl;

    return  0;
}
// -------------------------

/*
Timing: (AMD Phenom II X4 945 3000MHz)

 time ./bin 32
arg 1: 32 == n  [n-bit binary words]  default=5
 ct=4294967296
./bin 32  9.61s user 0.00s system 99% cpu 9.616 total
 ==> 2^32/9.61 == 446,926,877 per second

*/

/*
BENCHARGS=32
*/


/// Emacs:
/// Local Variables:
/// MyRelDir: "demo/bits"
/// makefile-dir: "../../"
/// make-target: "1demo DSRC=demo/bits/bit-sl-gray-demo.cc"
/// make-target2: "1demo DSRC=demo/bits/bit-sl-gray-demo.cc DEMOFLAGS=-DTIMING"
/// End:

