Exemplo n.º 1
0
Datum
cmsketch_empty(PG_FUNCTION_ARGS)
{
	CountMinSketch *cms = CountMinSketchCreate();
	SET_VARSIZE(cms, CountMinSketchSize(cms));
	PG_RETURN_POINTER(cms);
}
Exemplo n.º 2
0
CountMinSketch *
CountMinSketchCopy(CountMinSketch *cms)
{
	Size size = CountMinSketchSize(cms);
	char *new = palloc(size);
	memcpy(new, (char *) cms, size);
	return (CountMinSketch *) new;
}
Exemplo n.º 3
0
Datum
cmsketch_emptyp(PG_FUNCTION_ARGS)
{
	float8 eps = PG_GETARG_FLOAT8(0);
	float8 p = PG_GETARG_FLOAT8(1);
	CountMinSketch *cms = cmsketch_create(eps, p);
	SET_VARSIZE(cms, CountMinSketchSize(cms));
	PG_RETURN_POINTER(cms);
}
Exemplo n.º 4
0
CountMinSketch *
CountMinSketchCreateWithDAndW(uint32_t d, uint32_t w)
{
	CountMinSketch *cms = palloc0(sizeof(CountMinSketch) + (sizeof(uint32_t) * d * w));
	cms->d = d;
	cms->w = w;

	SET_VARSIZE(cms, CountMinSketchSize(cms));

	return cms;
}
Exemplo n.º 5
0
static CountMinSketch *
cmsketch_startup(FunctionCallInfo fcinfo, float8 eps, float8 p)
{
	CountMinSketch *cms;
	Oid type = AggGetInitialArgType(fcinfo);

	fcinfo->flinfo->fn_extra = lookup_type_cache(type, 0);

	if (p && eps)
		cms = cmsketch_create(eps, p);
	else
		cms = CountMinSketchCreate();

	SET_VARSIZE(cms, CountMinSketchSize(cms));

	return cms;
}
Exemplo n.º 6
0
Datum
cmsketch_print(PG_FUNCTION_ARGS)
{
	StringInfoData buf;
	CountMinSketch *cms;

	if (PG_ARGISNULL(0))
		PG_RETURN_NULL();

	cms = (CountMinSketch *) PG_GETARG_VARLENA_P(0);

	initStringInfo(&buf);
	appendStringInfo(&buf, "{ d = %d, w = %d, count = %ld, size = %ldkB }", cms->d, cms->w, cms->count, CountMinSketchSize(cms) / 1024);

	PG_RETURN_TEXT_P(CStringGetTextDatum(buf.data));
}
Exemplo n.º 7
0
Datum
cmsketch_out(PG_FUNCTION_ARGS)
{
	StringInfoData buf;
	CountMinSketch *cms = (CountMinSketch *) PG_GETARG_VARLENA_P(0);

	initStringInfo(&buf);
	appendStringInfo(&buf, "{ d = %d, w = %d, count = %d, size = %ldkB }", cms->d, cms->w, cms->count, CountMinSketchSize(cms) / 1024);

	PG_RETURN_CSTRING(buf.data);
}