MCPcopy Create free account
hub / github.com/apache/cloudberry / cube_inter

Function cube_inter

contrib/cube/cube.c:821–894  ·  view source on GitHub ↗

cube_inter */

Source from the content-addressed store, hash-verified

819
820/* cube_inter */
821Datum
822cube_inter(PG_FUNCTION_ARGS)
823{
824 NDBOX *a = PG_GETARG_NDBOX_P(0);
825 NDBOX *b = PG_GETARG_NDBOX_P(1);
826 NDBOX *result;
827 bool swapped = false;
828 int i;
829 int dim;
830 int size;
831
832 /* swap the arguments if needed, so that 'a' is always larger than 'b' */
833 if (DIM(a) < DIM(b))
834 {
835 NDBOX *tmp = b;
836
837 b = a;
838 a = tmp;
839 swapped = true;
840 }
841 dim = DIM(a);
842
843 size = CUBE_SIZE(dim);
844 result = (NDBOX *) palloc0(size);
845 SET_VARSIZE(result, size);
846 SET_DIM(result, dim);
847
848 /* First compute intersection of the dimensions present in both args */
849 for (i = 0; i < DIM(b); i++)
850 {
851 result->x[i] = Max(Min(LL_COORD(a, i), UR_COORD(a, i)),
852 Min(LL_COORD(b, i), UR_COORD(b, i)));
853 result->x[i + DIM(a)] = Min(Max(LL_COORD(a, i), UR_COORD(a, i)),
854 Max(LL_COORD(b, i), UR_COORD(b, i)));
855 }
856 /* continue on the higher dimensions only present in 'a' */
857 for (; i < DIM(a); i++)
858 {
859 result->x[i] = Max(0,
860 Min(LL_COORD(a, i), UR_COORD(a, i))
861 );
862 result->x[i + DIM(a)] = Min(0,
863 Max(LL_COORD(a, i), UR_COORD(a, i))
864 );
865 }
866
867 /*
868 * Check if the result was in fact a point, and set the flag in the datum
869 * accordingly. (we don't bother to repalloc it smaller)
870 */
871 if (cube_is_point_internal(result))
872 {
873 size = POINT_SIZE(dim);
874 result = repalloc(result, size);
875 SET_VARSIZE(result, size);
876 SET_POINT_BIT(result);
877 }
878

Callers

nothing calls this directly

Calls 3

cube_is_point_internalFunction · 0.85
palloc0Function · 0.50
repallocFunction · 0.50

Tested by

no test coverage detected