@@ -104,7 +104,7 @@ boolg_cube_internal_consistent(NDBOX *key, NDBOX *query, StrategyNumber strate
104104** Auxiliary funxtions
105105*/
106106static double distance_1D (double a1 ,double a2 ,double b1 ,double b2 );
107- static bool cube_is_point_internal (NDBOX * cube );
107+ static bool cube_is_point_internal (NDBOX * cube );
108108
109109
110110/*****************************************************************************
@@ -538,7 +538,7 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
538538rt_cube_size (datum_r ,& size_r );
539539
540540/*
541- * Now split up the regions between the two seeds. An important property
541+ * Now split up the regions between the two seeds. An important property
542542 * of this split algorithm is that the split vector v has the indices of
543543 * items to be split in order in its left and right vectors. We exploit
544544 * this property by doing a merge in the code that actually splits the
@@ -554,7 +554,7 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
554554{
555555/*
556556 * If we've already decided where to place this item, just put it on
557- * the right list. Otherwise, we need to figure out which page needs
557+ * the right list. Otherwise, we need to figure out which page needs
558558 * the least enlargement in order to store the item.
559559 */
560560
@@ -728,27 +728,27 @@ cube_union_v0(NDBOX *a, NDBOX *b)
728728SET_VARSIZE (result ,size );
729729SET_DIM (result ,dim );
730730
731- /* First compute the union of the dimensions present in both args */
731+ /* First compute the union of the dimensions present in both args */
732732for (i = 0 ;i < DIM (b );i ++ )
733733{
734734result -> x [i ]= Min (
735- Min (LL_COORD (a ,i ),UR_COORD (a ,i )),
736- Min (LL_COORD (b ,i ),UR_COORD (b ,i ))
737- );
735+ Min (LL_COORD (a ,i ),UR_COORD (a ,i )),
736+ Min (LL_COORD (b ,i ),UR_COORD (b ,i ))
737+ );
738738result -> x [i + DIM (a )]= Max (
739- Max (LL_COORD (a ,i ),UR_COORD (a ,i )),
740- Max (LL_COORD (b ,i ),UR_COORD (b ,i ))
741- );
739+ Max (LL_COORD (a ,i ),UR_COORD (a ,i )),
740+ Max (LL_COORD (b ,i ),UR_COORD (b ,i ))
741+ );
742742}
743743/* continue on the higher dimensions only present in 'a' */
744744for (;i < DIM (a );i ++ )
745745{
746746result -> x [i ]= Min (0 ,
747- Min (LL_COORD (a ,i ),UR_COORD (a ,i ))
748- );
747+ Min (LL_COORD (a ,i ),UR_COORD (a ,i ))
748+ );
749749result -> x [i + dim ]= Max (0 ,
750- Max (LL_COORD (a ,i ),UR_COORD (a ,i ))
751- );
750+ Max (LL_COORD (a ,i ),UR_COORD (a ,i ))
751+ );
752752}
753753
754754/*
@@ -795,6 +795,7 @@ cube_inter(PG_FUNCTION_ARGS)
795795if (DIM (a )< DIM (b ))
796796{
797797NDBOX * tmp = b ;
798+
798799b = a ;
799800a = tmp ;
800801swapped = true;
@@ -806,27 +807,27 @@ cube_inter(PG_FUNCTION_ARGS)
806807SET_VARSIZE (result ,size );
807808SET_DIM (result ,dim );
808809
809- /* First compute intersection of the dimensions present in both args */
810+ /* First compute intersection of the dimensions present in both args */
810811for (i = 0 ;i < DIM (b );i ++ )
811812{
812813result -> x [i ]= Max (
813- Min (LL_COORD (a ,i ),UR_COORD (a ,i )),
814- Min (LL_COORD (b ,i ),UR_COORD (b ,i ))
815- );
814+ Min (LL_COORD (a ,i ),UR_COORD (a ,i )),
815+ Min (LL_COORD (b ,i ),UR_COORD (b ,i ))
816+ );
816817result -> x [i + DIM (a )]= Min (
817- Max (LL_COORD (a ,i ),UR_COORD (a ,i )),
818- Max (LL_COORD (b ,i ),UR_COORD (b ,i ))
819- );
818+ Max (LL_COORD (a ,i ),UR_COORD (a ,i )),
819+ Max (LL_COORD (b ,i ),UR_COORD (b ,i ))
820+ );
820821}
821822/* continue on the higher dimemsions only present in 'a' */
822823for (;i < DIM (a );i ++ )
823824{
824825result -> x [i ]= Max (0 ,
825- Min (LL_COORD (a ,i ),UR_COORD (a ,i ))
826- );
826+ Min (LL_COORD (a ,i ),UR_COORD (a ,i ))
827+ );
827828result -> x [i + DIM (a )]= Min (0 ,
828- Max (LL_COORD (a ,i ),UR_COORD (a ,i ))
829- );
829+ Max (LL_COORD (a ,i ),UR_COORD (a ,i ))
830+ );
830831}
831832
832833/*
@@ -1236,14 +1237,14 @@ cube_distance(PG_FUNCTION_ARGS)
12361237/* compute within the dimensions of (b) */
12371238for (i = 0 ;i < DIM (b );i ++ )
12381239{
1239- d = distance_1D (LL_COORD (a ,i ),UR_COORD (a ,i ),LL_COORD (b ,i ),UR_COORD (b ,i ));
1240+ d = distance_1D (LL_COORD (a ,i ),UR_COORD (a ,i ),LL_COORD (b ,i ),UR_COORD (b ,i ));
12401241distance += d * d ;
12411242}
12421243
12431244/* compute distance to zero for those dimensions in (a) absent in (b) */
12441245for (i = DIM (b );i < DIM (a );i ++ )
12451246{
1246- d = distance_1D (LL_COORD (a ,i ),UR_COORD (a ,i ),0.0 ,0.0 );
1247+ d = distance_1D (LL_COORD (a ,i ),UR_COORD (a ,i ),0.0 ,0.0 );
12471248distance += d * d ;
12481249}
12491250
@@ -1297,11 +1298,11 @@ cube_is_point_internal(NDBOX *cube)
12971298return true;
12981299
12991300/*
1300- * Even if the point-flag is not set, all the lower-left coordinates
1301- *might match the upper-right coordinates, so that the value is in
1302- *fact a point. Such values don't arise with current code - the point
1303- *flag is always set if appropriate - but they might be present on-disk
1304- *in clusters upgraded from pre-9.4 versions.
1301+ * Even if the point-flag is not set, all the lower-left coordinates might
1302+ * match the upper-right coordinates, so that the value is in fact a
1303+ * point. Such values don't arise with current code - the point flag is
1304+ * always set if appropriate - but they might be present on-disk in
1305+ * clusters upgraded from pre-9.4 versions.
13051306 */
13061307for (i = 0 ;i < DIM (cube );i ++ )
13071308{
@@ -1317,6 +1318,7 @@ cube_dim(PG_FUNCTION_ARGS)
13171318{
13181319NDBOX * c = PG_GETARG_NDBOX (0 );
13191320int dim = DIM (c );
1321+
13201322PG_FREE_IF_COPY (c ,0 );
13211323PG_RETURN_INT32 (dim );
13221324}
@@ -1330,7 +1332,7 @@ cube_ll_coord(PG_FUNCTION_ARGS)
13301332double result ;
13311333
13321334if (DIM (c ) >=n && n > 0 )
1333- result = Min (LL_COORD (c ,n - 1 ),UR_COORD (c ,n - 1 ));
1335+ result = Min (LL_COORD (c ,n - 1 ),UR_COORD (c ,n - 1 ));
13341336else
13351337result = 0 ;
13361338
@@ -1347,7 +1349,7 @@ cube_ur_coord(PG_FUNCTION_ARGS)
13471349double result ;
13481350
13491351if (DIM (c ) >=n && n > 0 )
1350- result = Max (LL_COORD (c ,n - 1 ),UR_COORD (c ,n - 1 ));
1352+ result = Max (LL_COORD (c ,n - 1 ),UR_COORD (c ,n - 1 ));
13511353else
13521354result = 0 ;
13531355
@@ -1382,15 +1384,15 @@ cube_enlarge(PG_FUNCTION_ARGS)
13821384
13831385for (i = 0 ,j = dim ;i < DIM (a );i ++ ,j ++ )
13841386{
1385- if (LL_COORD (a ,i ) >=UR_COORD (a ,i ))
1387+ if (LL_COORD (a ,i ) >=UR_COORD (a ,i ))
13861388{
1387- result -> x [i ]= UR_COORD (a ,i )- r ;
1388- result -> x [j ]= LL_COORD (a ,i )+ r ;
1389+ result -> x [i ]= UR_COORD (a ,i )- r ;
1390+ result -> x [j ]= LL_COORD (a ,i )+ r ;
13891391}
13901392else
13911393{
1392- result -> x [i ]= LL_COORD (a ,i )- r ;
1393- result -> x [j ]= UR_COORD (a ,i )+ r ;
1394+ result -> x [i ]= LL_COORD (a ,i )- r ;
1395+ result -> x [j ]= UR_COORD (a ,i )+ r ;
13941396}
13951397if (result -> x [i ]> result -> x [j ])
13961398{
@@ -1503,7 +1505,7 @@ cube_c_f8(PG_FUNCTION_ARGS)
15031505result -> x [DIM (result )+ i ]= cube -> x [DIM (cube )+ i ];
15041506}
15051507result -> x [DIM (result )- 1 ]= x ;
1506- result -> x [2 * DIM (result )- 1 ]= x ;
1508+ result -> x [2 * DIM (result )- 1 ]= x ;
15071509}
15081510
15091511PG_FREE_IF_COPY (cube ,0 );
@@ -1521,7 +1523,8 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
15211523int size ;
15221524int i ;
15231525
1524- if (IS_POINT (cube )&& (x1 == x2 )){
1526+ if (IS_POINT (cube )&& (x1 == x2 ))
1527+ {
15251528size = POINT_SIZE ((DIM (cube )+ 1 ));
15261529result = (NDBOX * )palloc0 (size );
15271530SET_VARSIZE (result ,size );