24 #define ARRPTR(x) ( (double *) ARR_DATA_PTR(x) ) 25 #define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x)) 149 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
150 errmsg(
"cannot work with arrays containing NULLs")));
155 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
156 errmsg(
"can't extend cube"),
157 errdetail(
"A cube cannot have more than %d dimensions.",
162 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
163 errmsg(
"UR and LL arrays must be of same length")));
170 for (i = 0; i < dim; i++)
172 if (dur[i] != dll[i])
184 for (i = 0; i < dim; i++)
185 result->
x[i] = dur[i];
189 for (i = 0; i < dim; i++)
190 result->
x[i + dim] = dll[i];
213 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
214 errmsg(
"cannot work with arrays containing NULLs")));
219 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
220 errmsg(
"array is too long"),
221 errdetail(
"A cube cannot have more than %d dimensions.",
232 for (i = 0; i < dim; i++)
233 result->
x[i] = dur[i];
251 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
252 errmsg(
"cannot work with arrays containing NULLs")));
259 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
260 errmsg(
"array is too long"),
261 errdetail(
"A cube cannot have more than %d dimensions.",
272 for (i = 0; i < dim; i++)
274 if ((dx[i] <= 0) || (dx[i] >
DIM(c)))
276 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
277 errmsg(
"Index out of bounds")));
278 result->
x[
i] = c->
x[dx[
i] - 1];
280 result->
x[i + dim] = c->
x[dx[
i] +
DIM(c) - 1];
298 for (i = 0; i < dim; i++)
309 for (i = 0; i < dim; i++)
383 for (i = 1; i < entryvec->
n; i++)
442 *result = (float) (tmp1 - tmp2);
484 maxoff = entryvec->
n - 2;
507 size_waste = size_union - size_inter;
513 if (size_waste > waste || firsttime)
562 else if (i == seed_2)
577 if (size_alpha - size_l < size_beta - size_r)
718 for (i = 0; i <
DIM(b); i++)
726 for (; i <
DIM(a); i++)
728 result->
x[
i] =
Min(0,
731 result->
x[i + dim] =
Max(0,
771 bool swapped =
false;
793 for (i = 0; i <
DIM(b); i++)
801 for (; i <
DIM(a); i++)
803 result->
x[
i] =
Max(0,
858 if (a == (
NDBOX *) NULL)
871 for (i = 0; i <
DIM(a); i++)
888 for (i = 0; i < dim; i++)
897 for (i = 0; i < dim; i++)
910 for (i = dim; i <
DIM(a); i++)
917 for (i = dim; i <
DIM(a); i++)
933 for (i = dim; i <
DIM(b); i++)
940 for (i = dim; i <
DIM(b); i++)
1071 if ((a == NULL) || (b == NULL))
1081 for (i =
DIM(a); i <
DIM(b); i++)
1091 for (i = 0; i <
Min(
DIM(a),
DIM(b)); i++)
1141 if ((a == NULL) || (b == NULL))
1154 for (i = 0; i <
DIM(b); i++)
1163 for (i =
DIM(b); i <
DIM(a); i++)
1200 bool swapped =
false;
1217 for (i = 0; i <
DIM(b); i++)
1224 for (i =
DIM(b); i <
DIM(a); i++)
1249 bool swapped =
false;
1265 for (i = 0; i <
DIM(b); i++)
1270 for (i =
DIM(b); i <
DIM(a); i++)
1293 bool swapped =
false;
1310 for (i = 0; i <
DIM(b); i++)
1319 for (i =
DIM(b); i <
DIM(a); i++)
1356 bool inverse =
false;
1361 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
1362 errmsg(
"zero cube index is not defined")));
1371 if (coord <= 2 *
DIM(cube))
1374 int index = (coord - 1) / 2;
1377 bool upper = ((coord - 1) % 2 == 1);
1381 retval = cube->
x[index];
1389 retval =
Max(cube->
x[index], cube->
x[index +
DIM(cube)]);
1391 retval =
Min(cube->
x[index], cube->
x[index +
DIM(cube)]);
1403 retval =
Min(cube->
x[index], cube->
x[index +
DIM(cube)]);
1405 retval =
Max(cube->
x[index], cube->
x[index +
DIM(cube)]);
1437 elog(
ERROR,
"unrecognized cube strategy number: %d", strategy);
1449 if ((a1 <= b1) && (a2 <= b1) && (a1 <= b2) && (a2 <= b2))
1450 return (
Min(b1, b2) -
Max(a1, a2));
1453 if ((a1 > b1) && (a2 > b1) && (a1 > b2) && (a2 > b2))
1454 return (
Min(a1, a2) -
Max(b1, b2));
1487 for (i = 0; i <
DIM(cube); i++)
1514 if (
DIM(c) >= n && n > 0)
1531 if (
DIM(c) >= n && n > 0)
1551 if (coord <= 0 || coord > 2 *
DIM(cube))
1553 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
1554 errmsg(
"cube index %d is out of bounds", coord)));
1591 bool inverse =
false;
1597 (
errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
1598 errmsg(
"zero cube index is not defined")));
1607 if (coord <= 2 *
DIM(cube))
1610 int index = (coord - 1) / 2;
1613 bool upper = ((coord - 1) % 2 == 1);
1617 result = cube->
x[index];
1622 result =
Max(cube->
x[index], cube->
x[index +
DIM(cube)]);
1624 result =
Min(cube->
x[index], cube->
x[index +
DIM(cube)]);
1669 for (i = 0, j = dim; i <
DIM(a); i++, j++)
1681 if (result->
x[i] > result->
x[j])
1683 result->
x[
i] = (result->
x[
i] + result->
x[j]) / 2;
1684 result->
x[j] = result->
x[
i];
1688 for (; i < dim; i++, j++)
1771 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1772 errmsg(
"can't extend cube"),
1773 errdetail(
"A cube cannot have more than %d dimensions.",
1783 for (i = 0; i <
DIM(cube); i++)
1784 result->
x[i] = cube->
x[i];
1785 result->
x[DIM(result) - 1] = x;
1793 for (i = 0; i <
DIM(cube); i++)
1795 result->
x[
i] = cube->
x[
i];
1796 result->
x[
DIM(result) +
i] = cube->
x[
DIM(cube) +
i];
1798 result->
x[
DIM(result) - 1] = x;
1799 result->
x[2 *
DIM(result) - 1] = x;
1819 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1820 errmsg(
"can't extend cube"),
1821 errdetail(
"A cube cannot have more than %d dimensions.",
1831 for (i = 0; i <
DIM(cube); i++)
1832 result->
x[i] = cube->
x[i];
1833 result->
x[DIM(result) - 1] = x1;
1841 for (i = 0; i <
DIM(cube); i++)
1846 result->
x[
DIM(result) - 1] = x1;
1847 result->
x[2 *
DIM(result) - 1] = x2;
Datum cube_lt(PG_FUNCTION_ARGS)
#define PG_GETARG_FLOAT8(n)
#define PG_RETURN_POINTER(x)
int32 cube_cmp_v0(NDBOX *a, NDBOX *b)
Datum cube_distance(PG_FUNCTION_ARGS)
#define PG_GETARG_INT32(n)
Datum cube_ne(PG_FUNCTION_ARGS)
Datum cube_dim(PG_FUNCTION_ARGS)
#define RTOldContainsStrategyNumber
Datum distance_chebyshev(PG_FUNCTION_ARGS)
Datum cube_c_f8(PG_FUNCTION_ARGS)
#define RTOldContainedByStrategyNumber
char * float8out_internal(double num)
#define CubeKNNDistanceTaxicab
#define DatumGetNDBOXP(x)
Datum g_cube_distance(PG_FUNCTION_ARGS)
bool g_cube_leaf_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy)
#define PointerGetDatum(X)
#define PG_GETARG_DATUM(n)
#define CubeKNNDistanceEuclid
Datum cube_cmp(PG_FUNCTION_ARGS)
Datum cube_a_f8_f8(PG_FUNCTION_ARGS)
Datum cube_subset(PG_FUNCTION_ARGS)
#define PG_RETURN_FLOAT8(x)
#define PG_RETURN_INT32(x)
PG_FUNCTION_INFO_V1(cube_in)
int errcode(int sqlerrcode)
bool g_cube_internal_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy)
void cube_scanner_init(const char *str)
Datum idx(PG_FUNCTION_ARGS)
#define RTContainedByStrategyNumber
#define PG_GETARG_POINTER(n)
Datum upper(PG_FUNCTION_ARGS)
bool cube_overlap_v0(NDBOX *a, NDBOX *b)
Datum cube_f8(PG_FUNCTION_ARGS)
#define PG_GETARG_NDBOX_P(x)
Datum g_cube_compress(PG_FUNCTION_ARGS)
Datum cube_enlarge(PG_FUNCTION_ARGS)
Datum cube_ll_coord(PG_FUNCTION_ARGS)
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
Datum distance_taxicab(PG_FUNCTION_ARGS)
static const FormData_pg_attribute a2
#define PG_GETARG_ARRAYTYPE_P(n)
static double distance_1D(double a1, double a2, double b1, double b2)
Datum cube_size(PG_FUNCTION_ARGS)
#define CubeKNNDistanceChebyshev
void cube_scanner_finish(void)
#define LL_COORD(cube, i)
Datum cube_contains(PG_FUNCTION_ARGS)
Datum g_cube_penalty(PG_FUNCTION_ARGS)
void cube_yyerror(NDBOX **result, const char *message) pg_attribute_noreturn()
Datum cube_union(PG_FUNCTION_ARGS)
void appendStringInfoString(StringInfo str, const char *s)
Datum g_cube_picksplit(PG_FUNCTION_ARGS)
Datum cube_inter(PG_FUNCTION_ARGS)
#define FirstOffsetNumber
int errdetail(const char *fmt,...)
#define RTSameStrategyNumber
Datum cube_coord(PG_FUNCTION_ARGS)
Datum cube_a_f8(PG_FUNCTION_ARGS)
Datum g_cube_same(PG_FUNCTION_ARGS)
#define GistPageIsLeaf(page)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
NDBOX * g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep)
void * palloc0(Size size)
Datum cube_f8_f8(PG_FUNCTION_ARGS)
void rt_cube_size(NDBOX *a, double *sz)
#define DatumGetFloat8(X)
#define PG_RETURN_BOOL(x)
#define PG_RETURN_DATUM(x)
Datum g_cube_decompress(PG_FUNCTION_ARGS)
Datum cube_in(PG_FUNCTION_ARGS)
#define ereport(elevel,...)
Datum cube_is_point(PG_FUNCTION_ARGS)
Datum cube_contained(PG_FUNCTION_ARGS)
Datum cube_out(PG_FUNCTION_ARGS)
Datum cube_c_f8_f8(PG_FUNCTION_ARGS)
#define gistentryinit(e, k, r, pg, o, l)
#define PG_RETURN_NDBOX_P(x)
#define PG_RETURN_CSTRING(x)
#define OffsetNumberNext(offsetNumber)
double x[FLEXIBLE_ARRAY_MEMBER]
#define PG_FREE_IF_COPY(ptr, n)
#define RTContainsStrategyNumber
void * repalloc(void *pointer, Size size)
Datum cube_le(PG_FUNCTION_ARGS)
#define PG_GETARG_UINT16(n)
NDBOX * cube_union_v0(NDBOX *a, NDBOX *b)
int cube_yyparse(NDBOX **result)
int errmsg(const char *fmt,...)
#define SET_POINT_BIT(cube)
#define SET_DIM(cube, _dim)
Datum cube_overlap(PG_FUNCTION_ARGS)
Datum cube_ge(PG_FUNCTION_ARGS)
#define PG_GETARG_CSTRING(n)
#define RTOverlapStrategyNumber
#define SET_VARSIZE(PTR, len)
#define CubeKNNDistanceCoord
static const FormData_pg_attribute a1
static bool cube_is_point_internal(NDBOX *cube)
Datum cube_coord_llur(PG_FUNCTION_ARGS)
#define UR_COORD(cube, i)
bool array_contains_nulls(ArrayType *array)
bool cube_contains_v0(NDBOX *a, NDBOX *b)
#define DirectFunctionCall2(func, arg1, arg2)
Datum cube_eq(PG_FUNCTION_ARGS)
Datum cube_gt(PG_FUNCTION_ARGS)
Datum g_cube_union(PG_FUNCTION_ARGS)
Datum cube_ur_coord(PG_FUNCTION_ARGS)
Datum g_cube_consistent(PG_FUNCTION_ARGS)