void simplify_astates() /* simplifies the alternating automaton */
{
    ATrans *t;
    int i, *acc = make_set(-1, 0); /* no state is accessible initially */

    for (t = transition[0]; t; t = t->nxt, i = 0)
    {
        merge_sets(acc, t->to, 0);    /* all initial states are accessible */
    }

    for (i = node_id - 1; i > 0; i--)
    {
        if (!in_set(acc, i))   /* frees unaccessible states */
        {
            label[i] = ZN;
            free_atrans(transition[i], 1);
            transition[i] = (ATrans *)0;
            continue;
        }
        astate_count++;
        simplify_atrans(&transition[i]);
        for (t = transition[i]; t; t = t->nxt)
        {
            merge_sets(acc, t->to, 0);
        }
    }

    tfree(acc);
}
Example #2
0
Datum hll_sum(PG_FUNCTION_ARGS) {
	MemoryContext aggctx;
    MemoryContext tmpcontext;
    MemoryContext oldcontext;

	dmerge_state *state;
	uint32_t     *value;
    uLongf dest_size = HLL_LEN * 4;
	int unpack_res;
	int count;
	int i;

	bytea    *data = PG_GETARG_BYTEA_P(1);

	if (!AggCheckCallContext(fcinfo, &aggctx))
        ereport(ERROR,
                (errcode(ERRCODE_DATA_EXCEPTION),
                 errmsg("hll_sum outside transition context")));


	if ( PG_ARGISNULL(0) ) {
		tmpcontext = AllocSetContextCreate(aggctx,
		                                   "hll_sum",
		                                   ALLOCSET_DEFAULT_MINSIZE,
		                                   ALLOCSET_DEFAULT_INITSIZE,
		                                   ALLOCSET_DEFAULT_MAXSIZE);

	    oldcontext = MemoryContextSwitchTo(tmpcontext);
		state = (dmerge_state *) palloc(sizeof(dmerge_state));
	    MemoryContextSwitchTo(oldcontext);

		value = state->state;
	} else {
		state = (dmerge_state *) PG_GETARG_POINTER(0);
		value = state->value;
	}

    unpack_res = uncompress((Bytef *) value, &dest_size, (Bytef *) VARDATA(data), VARSIZE(data));
    if ( unpack_res != Z_OK ) {
		ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("can't decode value")));
    }

    count = dest_size / 4;
    for(i = 0; i < count; i++) {
    	value[i] = ntohl(value[i]);
    }

	if ( !PG_ARGISNULL(0) ) {
		merge_sets(1 << state->state[0], value + 2, state->state + 2);
	}

	PG_RETURN_POINTER(state);
}
Example #3
0
Datum hll_merge(PG_FUNCTION_ARGS) {
	bytea    *state;
	uint32_t *sdata;

	bytea    *value = PG_GETARG_BYTEA_P(1);
	uint32_t *vdata = (uint32_t *) VARDATA(value);

	if ( PG_ARGISNULL(0) ) {
		PG_RETURN_BYTEA_P(value);
	} else {
		state = PG_GETARG_BYTEA_P(0);
		sdata = (uint32_t *) VARDATA(state);
	}

	merge_sets(1 << sdata[0], vdata + 2, sdata + 2);
	PG_RETURN_BYTEA_P(state);
}