#include <stdio.h>
#include <stdlib.h>

unsigned long long
atoull(char *a)
{
    unsigned long long val = 0;
    /* crude, no wraparound checks */
    while (*a >= '0' && *a <= '9')
    {
        val = val * 10 + *a - '0';
        a++;
    }
    return val;
}

int
main(int argc, char **argv)
{
    unsigned long long reltuples;
    float scale_factor;
    unsigned long long threshold;
    unsigned long long n_vacuums;
    unsigned long long n_inserts;
    unsigned long long max_tuples;

    if (argc < 4)
    {
        fprintf(stderr, "Syntax %s <scale_factor> <threshold> <maximum table size in rows>\n", argv[0]);
        return -1;
    }


    scale_factor = atof(argv[1]);
    threshold = atoull(argv[2]);
    max_tuples = atoull(argv[3]);
    reltuples = 1;
    n_vacuums = 0;

    printf("scale_factor = %g, threshold = %llu\n", scale_factor, threshold);

    for(;;)
    {
        n_inserts = threshold + reltuples * scale_factor + 1;

        /* do "vacuum" */
        n_vacuums++;
        reltuples += n_inserts;

        if (reltuples > max_tuples)
            break;
        printf("Vacuum %llu at %llu reltuples, %llu inserts\n", n_vacuums, reltuples, n_inserts);
    }

    return 0;
}
