Datum cmsketch_empty(PG_FUNCTION_ARGS) { CountMinSketch *cms = CountMinSketchCreate(); SET_VARSIZE(cms, CountMinSketchSize(cms)); PG_RETURN_POINTER(cms); }
CountMinSketch * CountMinSketchCopy(CountMinSketch *cms) { Size size = CountMinSketchSize(cms); char *new = palloc(size); memcpy(new, (char *) cms, size); return (CountMinSketch *) new; }
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); }
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; }
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; }
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)); }
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); }