PostGIS  2.1.10dev-r@@SVN_REVISION@@
static CIRC_NODE * circ_nodes_merge ( CIRC_NODE **  nodes,
int  num_nodes 
)
static

Definition at line 383 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().

384 {
385  CIRC_NODE **inodes = NULL;
386  int num_children = num_nodes;
387  int inode_num = 0;
388  int num_parents = 0;
389  int j;
390 
391  // TODO, roll geom_type *up* as tree is built, changing to collection types as simple types are merged
392  // TODO, change the distance algorithm to drive down to simple types first, test pip on poly/other cases, then test edges
393 
394  while( num_children > 1 )
395  {
396  for ( j = 0; j < num_children; j++ )
397  {
398  inode_num = (j % CIRC_NODE_SIZE);
399  if ( inode_num == 0 )
400  inodes = lwalloc(sizeof(CIRC_NODE*)*CIRC_NODE_SIZE);
401 
402  inodes[inode_num] = nodes[j];
403 
404  if ( inode_num == CIRC_NODE_SIZE-1 )
405  nodes[num_parents++] = circ_node_internal_new(inodes, CIRC_NODE_SIZE);
406  }
407 
408  /* Clean up any remaining nodes... */
409  if ( inode_num == 0 )
410  {
411  /* Promote solo nodes without merging */
412  nodes[num_parents++] = inodes[0];
413  lwfree(inodes);
414  }
415  else if ( inode_num < CIRC_NODE_SIZE-1 )
416  {
417  /* Merge spare nodes */
418  nodes[num_parents++] = circ_node_internal_new(inodes, inode_num+1);
419  }
420 
421  num_children = num_parents;
422  num_parents = 0;
423  }
424 
425  /* Return a reference to the head of the tree */
426  return nodes[0];
427 }
#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:190
void * lwalloc(size_t size)
Definition: lwutil.c:175
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: