PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ circ_nodes_merge()

static CIRC_NODE * circ_nodes_merge ( CIRC_NODE **  nodes,
int  num_nodes 
)
static

Definition at line 408 of file lwgeodetic_tree.c.

References circ_node_internal_new(), CIRC_NODE_SIZE, lwalloc(), and lwfree().

Referenced by circ_tree_new(), lwcollection_calculate_circ_tree(), and lwpoly_calculate_circ_tree().

409 {
410  CIRC_NODE **inodes = NULL;
411  int num_children = num_nodes;
412  int inode_num = 0;
413  int num_parents = 0;
414  int j;
415 
416  /* TODO, roll geom_type *up* as tree is built, changing to collection types as simple types are merged
417  * TODO, change the distance algorithm to drive down to simple types first, test pip on poly/other cases, then test edges
418  */
419 
420  while( num_children > 1 )
421  {
422  for ( j = 0; j < num_children; j++ )
423  {
424  inode_num = (j % CIRC_NODE_SIZE);
425  if ( inode_num == 0 )
426  inodes = lwalloc(sizeof(CIRC_NODE*)*CIRC_NODE_SIZE);
427 
428  inodes[inode_num] = nodes[j];
429 
430  if ( inode_num == CIRC_NODE_SIZE-1 )
431  nodes[num_parents++] = circ_node_internal_new(inodes, CIRC_NODE_SIZE);
432  }
433 
434  /* Clean up any remaining nodes... */
435  if ( inode_num == 0 )
436  {
437  /* Promote solo nodes without merging */
438  nodes[num_parents++] = inodes[0];
439  lwfree(inodes);
440  }
441  else if ( inode_num < CIRC_NODE_SIZE-1 )
442  {
443  /* Merge spare nodes */
444  nodes[num_parents++] = circ_node_internal_new(inodes, inode_num+1);
445  }
446 
447  num_children = num_parents;
448  num_parents = 0;
449  }
450 
451  /* Return a reference to the head of the tree */
452  return nodes[0];
453 }
#define CIRC_NODE_SIZE
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
void lwfree(void *mem)
Definition: lwutil.c:244
void * lwalloc(size_t size)
Definition: lwutil.c:229
static CIRC_NODE * circ_node_internal_new(CIRC_NODE **c, int num_nodes)
Create a new internal node, calculating the new measure range for the node, and storing pointers to t...
Here is the call graph for this function:
Here is the caller graph for this function: