#include "sets.h"
#include "longlong.h"
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

SSET RandomSSet(void)
{
    SSET ss;
    int i;
    SSetReset(ss);
    for(i=0; i<64; i++)
	if(drand48() < 0.5)
	    SSetAdd(ss, i);
    return ss;
}

int main(int argc, char *argv[])
{
    int n = atoi(argv[1]), i;
    SSET array[n];
    SSETDICT *ssd = SSetDictAlloc(2);
    char word[65];

    srand48(time(NULL)+getpid());

    for(i=0; i<n; i++)
    {
	array[i] = RandomSSet();
	if(SSetDictIn(ssd, array[i]))
	    printf("random %s already in???\n", SSetToString(65, word, array[i]));

	SSetDictAdd(ssd, array[i]);
	if(!SSetDictIn(ssd, array[i]))
	{
	    printf("array[%d]=%s not in ssd immediately after insertion\n",
		i, SSetToString(65, word, array[i]));
	}
    }

    for(i=0; i<n; i++)
    {
	SSET ss;
	if(!SSetDictIn(ssd, array[i]))
	{
	    printf("array[%d]=%s not in ssd after all insertions\n",
		i, SSetToString(65, word, array[i]));
	}
	ss = RandomSSet();
	if(SSetDictIn(ssd, ss))
	{
	    printf("unexpected random %s found\n", SSetToString(65, word, ss));
	}
    }

    return 0;
}
