338{
339 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
340 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
342 int median, i;
343 double *lowXs = palloc(sizeof(double) * in->nTuples);
344 double *highXs = palloc(sizeof(double) * in->nTuples);
345 double *lowYs = palloc(sizeof(double) * in->nTuples);
346 double *highYs = palloc(sizeof(double) * in->nTuples);
347
348
349 for (i = 0; i < in->nTuples; i++)
350 {
351 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
352
353 lowXs[i] = (double)box->xmin;
354 highXs[i] = (double)box->xmax;
355 lowYs[i] = (double)box->ymin;
356 highYs[i] = (double)box->ymax;
357 }
358
363
364 median = in->nTuples / 2;
365
367
368 centroid->xmin = (float)lowXs[median];
369 centroid->xmax = (float)highXs[median];
370 centroid->ymin = (float)lowYs[median];
371 centroid->ymax = (float)highYs[median];
372
373
374 out->hasPrefix = true;
375 out->prefixDatum = PointerGetDatum(
centroid);
376
377 out->nNodes = 16;
378 out->nodeLabels = NULL;
379
380 out->mapTuplesToNodes = palloc(sizeof(int) * in->nTuples);
381 out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
382
383
384
385
386 for (i = 0; i < in->nTuples; i++)
387 {
388 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
390
391 out->leafTupleDatums[i] = PointerGetDatum(box);
392 out->mapTuplesToNodes[i] = quadrant;
393 }
394
395 pfree(lowXs);
396 pfree(highXs);
397 pfree(lowYs);
398 pfree(highYs);
399
400 PG_RETURN_VOID();
401}
static int compareDoubles(const void *a, const void *b)
static uint8 getQuadrant4D(BOX2DF *centroid, BOX2DF *inBox)
Datum centroid(PG_FUNCTION_ARGS)