Exemplo n.º 1
0
int main(int argc, char *argv[])
{
#ifdef FAIL
	int *g = gen1();
#else
	generator_t(int) g = gen1();
#endif

	printf("%d", *generator_next(g));

	exit(0);
}
Exemplo n.º 2
0
/*
 * statext_ndistinct_build
 *		Compute ndistinct coefficient for the combination of attributes.
 *
 * This computes the ndistinct estimate using the same estimator used
 * in analyze.c and then computes the coefficient.
 */
MVNDistinct *
statext_ndistinct_build(double totalrows, int numrows, HeapTuple *rows,
						Bitmapset *attrs, VacAttrStats **stats)
{
	MVNDistinct *result;
	int			k;
	int			itemcnt;
	int			numattrs = bms_num_members(attrs);
	int			numcombs = num_combinations(numattrs);

	result = palloc(offsetof(MVNDistinct, items) +
					numcombs * sizeof(MVNDistinctItem));
	result->magic = STATS_NDISTINCT_MAGIC;
	result->type = STATS_NDISTINCT_TYPE_BASIC;
	result->nitems = numcombs;

	itemcnt = 0;
	for (k = 2; k <= numattrs; k++)
	{
		int		   *combination;
		CombinationGenerator *generator;

		/* generate combinations of K out of N elements */
		generator = generator_init(numattrs, k);

		while ((combination = generator_next(generator)))
		{
			MVNDistinctItem *item = &result->items[itemcnt];
			int			j;

			item->attrs = NULL;
			for (j = 0; j < k; j++)
				item->attrs = bms_add_member(item->attrs,
											 stats[combination[j]]->attr->attnum);
			item->ndistinct =
				ndistinct_for_combination(totalrows, numrows, rows,
										  stats, k, combination);

			itemcnt++;
			Assert(itemcnt <= result->nitems);
		}

		generator_free(generator);
	}

	/* must consume exactly the whole output array */
	Assert(itemcnt == result->nitems);

	return result;
}
Exemplo n.º 3
0
int main() {
    struct node *binary_tree=NULL, *tmp;
    struct generator *g_ints;
    struct generator *g_bt;
    int *x;
    int y=190;
    x = &y;
    g_ints = generator_start((void*)(x), integer_next, integer_stop);
    while ((x = (int*)generator_next(g_ints)) != NULL ) {
        printf("%d\n", *x);
    }

    /**
     * Make a tree look like this
     *               7
     *      3                11
     *   2      5       8         14
     * 1                  10
     */
    insert(&binary_tree, 7);
    insert(&binary_tree, 3);
    insert(&binary_tree, 2);
    insert(&binary_tree, 1);
    insert(&binary_tree, 5);
    insert(&binary_tree, 11);
    insert(&binary_tree, 8);
    insert(&binary_tree, 10);
    insert(&binary_tree, 14);
    g_bt = generator_start((void*)binary_tree, bt_next, bt_stop);
    // I have to think of an elegant solution to go back nodes
    // F**K
    while ((tmp = (struct node *)generator_next(g_bt)) != NULL) {
        printf("%d\n", tmp->val);
    }
    return 0;
}