in src/aod_sketch_pg_functions.c [507:537]
Datum pg_aod_sketch_intersection(PG_FUNCTION_ARGS) {
const bytea* bytes_in1;
const bytea* bytes_in2;
void* sketchptr1;
void* sketchptr2;
void* interptr;
void* sketchptr;
struct ptr_with_size bytes_out;
int num_values;
num_values = PG_NARGS() > 2 ? PG_GETARG_INT32(2) : 1;
interptr = aod_intersection_new(num_values);
if (!PG_ARGISNULL(0)) {
bytes_in1 = PG_GETARG_BYTEA_P(0);
sketchptr1 = aod_sketch_deserialize(VARDATA(bytes_in1), VARSIZE(bytes_in1) - VARHDRSZ);
aod_intersection_update(interptr, sketchptr1);
compact_aod_sketch_delete(sketchptr1);
}
if (!PG_ARGISNULL(1)) {
bytes_in2 = PG_GETARG_BYTEA_P(1);
sketchptr2 = aod_sketch_deserialize(VARDATA(bytes_in2), VARSIZE(bytes_in2) - VARHDRSZ);
aod_intersection_update(interptr, sketchptr2);
compact_aod_sketch_delete(sketchptr2);
}
sketchptr = aod_intersection_get_result(interptr);
aod_intersection_delete(interptr);
bytes_out = aod_sketch_serialize(sketchptr, VARHDRSZ);
compact_aod_sketch_delete(sketchptr);
SET_VARSIZE(bytes_out.ptr, bytes_out.size);
PG_RETURN_BYTEA_P(bytes_out.ptr);
}