Set RtreeInfo to indicate nearest-neighbor functions

This C code fragment shows how to set the RtreeInfo support function to indicate that a strategy function is a nearest-neighbor function, and that a nearest-neighbor function exists that makes approximate distance calculations. To do this, use the operation keys (operation_ptr arguments), nearest_neighbor_functions, and bbox_only_distance, respectively. You can combine this fragment with the example shown in C code example for the RtreeInfo support function.

For each operation (nearest_neighbor_functions and bbox_only_distance), if the answer_ptr argument is NULL, the function should return either MI_OK or RLT_OP_UNSUPPORTED, depending whether that operation is supported.

If the answer_ptr argument is not NULL, it is a pointer to a pointer to an MI_LVARCHAR containing an array of 64 MI_BOOLEANS, one for each strategy function slot (allocated by the caller). For the nearest_neighbor_functions operation, the RtreeInfo function should fill in either MI_TRUE or MI_FALSE for each entry corresponding to a nearest-neighbor strategy function. For the bbox_only_distance operation, the RtreeInfo function should fill in MI_TRUE to indicate that the distance function uses bounding-box measurements only or MI_FALSE to indicate that exact calculation distance calculations are required. If the bbox_only_distance operation is not supported, the R-tree access method assumes that exact distance calculations are required.
...
else if (matches(operation, “nearest_neighbor_functions”))
  {
  /*
  ** Indicate which strategy functions are nearest-neighbor
  ** functions. In this case, the 6th strategy function.
  */
  mi_boolean *answer = NULL;

  if (answer_ptr == NULL)
      goto done; /* Operation is supported */

  /* Memory for 64 booleans is allocated by R-tree */
  answer = (mi_boolean*) mi_get_vardata((mi_lvarchar*)
           mi_get_vardata(answer_ptr));

  answer[0] = MI_FALSE; /* intersect */
  answer[1] = MI_FALSE; /* equal     */
  answer[2] = MI_FALSE; /* contains  */
  answer[3] = MI_FALSE; /* inside    */
  answer[4] = MI_FALSE; /* outside   */
  answer[5] = MI_TRUE;  /* nearest   */

  }

else if (matches(operation, “bbox_only_distance”))
  {
  /*
  ** Indicate which nearest-neighbor distance functions
  ** do their calculation using only bounding box information,
  ** giving an approximate distance. In this case, the 7th 
  ** strategy function.
  */
  mi_boolean *answer = NULL;

  if (answer_ptr == NULL)
      goto done; /* Operation is supported */

  /* Memory for 64 booleans is allocated by R-tree */
  answer = (mi_boolean*) mi_get_vardata((mi_lvarchar*)
  (mi_get_vardata(answer_ptr));

  if (answer == NULL)
      {
       status = MI_ERROR;
       goto bad;
      }

  answer[0] = MI_FALSE; /* intersect   */
  answer[1] = MI_FALSE; /* equal       */
  answer[2] = MI_FALSE; /* contains    */
  answer[3] = MI_FALSE; /* inside      */
  answer[4] = MI_FALSE; /* outside     */
  answer[5] = MI_FALSE; /* nearest     */
  answer[6] = MI_TRUE;  /* nearest_bbox*/


  }

Copyright© 2019 HCL Technologies Limited