#include "postgres.h" #include "utils/array.h" #include "cubedata.h" /* contrib/cube */ /* ** CREATE OR REPLACE FUNCTION cube_from_arrays(float[], float[]) RETURNS cube ** AS 'ordermatch' ** LANGUAGE C; */ NDBOX *cube_from_arrays (ArrayType *ur, ArrayType *ll); /* ** Taken from the intarray contrib header */ #define ARRPTR(x) ( (double *) ARR_DATA_PTR(x) ) #define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x)) /* ** Allows the construction of a cube from 2 float[]'s */ NDBOX *cube_from_arrays (ArrayType *ur, ArrayType *ll) { int i; int dim; int size; NDBOX *result; double *dur, *dll; dim = ARRNELEMS(ur); if (ARRNELEMS(ll) < dim) { /* ** If the array's are not of equal length, use the length ** of the shorter array. */ dim = ARRNELEMS(ll); } dur = ARRPTR(ur); dll = ARRPTR(ll); size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim; result = (NDBOX *) palloc (size); memset (result, 0, size); result->size = size; result->dim = dim; for (i=0; ix[i] = dur[i]; result->x[i+dim] = dll[i]; } return result; }