PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_penalty()

Datum gserialized_gist_penalty ( PG_FUNCTION_ARGS  )

Definition at line 1344 of file gserialized_gist_nd.c.

1345 {
1346  GISTENTRY *origentry = (GISTENTRY*) PG_GETARG_POINTER(0);
1347  GISTENTRY *newentry = (GISTENTRY*) PG_GETARG_POINTER(1);
1348  float *result = (float*) PG_GETARG_POINTER(2);
1349  GIDX *gbox_index_orig, *gbox_index_new;
1350  float size_union, size_orig, edge_union, edge_orig;
1351 
1352  POSTGIS_DEBUG(4, "[GIST] 'penalty' function called");
1353 
1354  gbox_index_orig = (GIDX*)DatumGetPointer(origentry->key);
1355  gbox_index_new = (GIDX*)DatumGetPointer(newentry->key);
1356 
1357  /* Drop out if we're dealing with null inputs. Shouldn't happen. */
1358  if ( (gbox_index_orig == NULL) && (gbox_index_new == NULL) )
1359  {
1360  POSTGIS_DEBUG(4, "[GIST] both inputs NULL! returning penalty of zero");
1361  *result = 0.0;
1362  PG_RETURN_FLOAT8(*result);
1363  }
1364 
1365  /* Calculate the size difference of the boxes (volume difference in this case). */
1366  size_union = gidx_union_volume(gbox_index_orig, gbox_index_new);
1367  size_orig = gidx_volume(gbox_index_orig);
1368  *result = size_union - size_orig;
1369 
1370  /* REALM 0: No extension is required, volume is zero, return edge */
1371  /* REALM 1: No extension is required, return nonzero area */
1372  /* REALM 2: Area extension is zero, return nonzero edge extension */
1373  /* REALM 3: Area extension is nonzero, return it */
1374 
1375  if( *result == 0 )
1376  {
1377  if (size_orig > 0)
1378  {
1379  *result = pack_float(size_orig, 1); /* REALM 1 */
1380  }
1381  else
1382  {
1383  edge_union = gidx_union_edge(gbox_index_orig, gbox_index_new);
1384  edge_orig = gidx_edge(gbox_index_orig);
1385  *result = edge_union - edge_orig;
1386  if( *result == 0 )
1387  {
1388  *result = pack_float(edge_orig, 0); /* REALM 0 */
1389  }
1390  else
1391  {
1392  *result = pack_float(*result, 2); /* REALM 2 */
1393  }
1394  }
1395  }
1396  else
1397  {
1398  *result = pack_float(*result, 3); /* REALM 3 */
1399  }
1400 
1401  POSTGIS_DEBUGF(4, "[GIST] union size (%.12f), original size (%.12f), penalty (%.12f)", size_union, size_orig, *result);
1402 
1403  PG_RETURN_POINTER(result);
1404 }
static float gidx_union_volume(GIDX *a, GIDX *b)
static float pack_float(const float value, const int realm)
static float gidx_union_edge(GIDX *a, GIDX *b)
static float gidx_volume(GIDX *a)
static float gidx_edge(GIDX *a)

References gidx_edge(), gidx_union_edge(), gidx_union_volume(), gidx_volume(), and pack_float().

Referenced by gserialized_gist_picksplit_constructsplit().

Here is the call graph for this function:
Here is the caller graph for this function: