315 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
316 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
318 float *lowXs, *highXs;
319 int ndims, maxdims = -1,
count[GIDX_MAX_DIM], median, dim, tuple;
321 for (dim = 0; dim < GIDX_MAX_DIM; dim++)
324 lowXs = palloc(
sizeof(
float) * in->nTuples * GIDX_MAX_DIM),
325 highXs = palloc(
sizeof(
float) * in->nTuples * GIDX_MAX_DIM);
328 for (tuple = 0; tuple < in->nTuples; tuple++)
330 box = (GIDX *)DatumGetPointer(in->datums[tuple]);
331 ndims = GIDX_NDIMS(box);
334 for (dim = 0; dim < ndims; dim++)
337 if (GIDX_GET_MAX(box, dim) != FLT_MAX)
339 lowXs[dim * in->nTuples +
count[dim]] = GIDX_GET_MIN(box, dim);
340 highXs[dim * in->nTuples +
count[dim]] = GIDX_GET_MAX(box, dim);
346 for (dim = 0; dim < maxdims; dim++)
352 centroid = (GIDX *)palloc(GIDX_SIZE(maxdims));
353 SET_VARSIZE(
centroid, GIDX_SIZE(maxdims));
355 for (dim = 0; dim < maxdims; dim++)
357 median =
count[dim] / 2;
358 GIDX_SET_MIN(
centroid, dim, lowXs[dim * in->nTuples + median]);
359 GIDX_SET_MAX(
centroid, dim, highXs[dim * in->nTuples + median]);
363 out->hasPrefix =
true;
366 out->nNodes = 0x01 << (2 * maxdims);
367 out->nodeLabels = NULL;
369 out->mapTuplesToNodes = palloc(
sizeof(
int) * in->nTuples);
370 out->leafTupleDatums = palloc(
sizeof(Datum) * in->nTuples);
376 for (tuple = 0; tuple < in->nTuples; tuple++)
378 GIDX *box = (GIDX *)DatumGetPointer(in->datums[tuple]);
381 out->leafTupleDatums[tuple] = PointerGetDatum(box);
382 out->mapTuplesToNodes[tuple] = octant;
GIDX * gidx_copy(GIDX *b)
static uint16_t getOctant(GIDX *centroid, GIDX *inBox)
static int compareFloats(const void *a, const void *b)
Datum centroid(PG_FUNCTION_ARGS)