
#include "comb/setpart-rgs-lex.h"

// demo-include "comb/setpart-rgs-lex.cc"

//#include "jjassert.h"
#include "fxtiomanip.h"
#include "fxttypes.h"

#include "demo/nextarg.h"

//% Set partitions as restricted growth strings (RGS).


//#define TIMING // uncomment to disable printing


int
main(int argc, char **argv)
{
    ulong n = 5;
    NXARG(n, "Partition set of n elements");
//    ulong px = 0;
//    NXARG(px, "If !=0, only list partitions into exactly px sets");
    bool bq = false;
    NXARG(bq, "whether to list backwards");

    setpart_rgs_lex P(n);
    if ( bq )  P.last();

    ulong ct = 0;

#ifdef TIMING
    if ( bq )  { do { ++ct; }  while ( P.prev() ); }
    else       { do { ++ct; }  while ( P.next() ); }

#else

    do
    {
//        if ( px && (P.m_[n]!=px) )  continue;
        ++ct;
        cout << setw(3) << ct << ":  ";
        P.print();
        cout << "    ";  P.print_set();
        cout << endl;
    }
    while ( bq ? P.prev() : P.next() );
#endif

    cout << " ct = " << ct << endl;

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

/*
Timing:

 time ./bin 15 0
arg 1: 15 == n  [Partition set of n elements]  default=5
arg 3: 0 == bq  [whether to list backwards]  default=0
 ct = 1382958545
./bin 15 0  8.79s user 0.03s system 99% cpu 8.822 total
 ==> 1382958545/8.79 == 157,333,167 per second

 time ./bin 15 1
arg 1: 15 == n  [Partition set of n elements]  default=5
arg 3: 1 == bq  [whether to list backwards]  default=0
 ct = 1382958545
./bin 15 1  7.28s user 0.01s system 100% cpu 7.286 total
 ==> 1382958545/7.28 == 189,966,833 per second

*/


/// Emacs:
/// Local Variables:
/// MyRelDir: "demo/comb"
/// makefile-dir: "../../"
/// make-target: "1demo DSRC=demo/comb/setpart-rgs-lex-demo.cc"
/// make-target2: "1demo DSRC=demo/comb/setpart-rgs-lex-demo.cc DEMOFLAGS=-DTIMING"
/// End:

