PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ itree_merge_nodes()

static uint32_t itree_merge_nodes ( IntervalTree itree,
uint32_t  nodes_remaining 
)
static

Definition at line 116 of file intervaltree.c.

117  {
118  /*
119  * store the starting state of the tree which gives
120  * us the array of nodes we are going to have to merge
121  */
122  uint32_t end_node = itree->numNodes;
123  uint32_t start_node = end_node - nodes_remaining;
124 
125  /*
126  * one parent for every ITREE_MAX_NODES children
127  * plus one for the remainder
128  */
129  uint32_t num_parents = nodes_remaining / ITREE_MAX_NODES;
130  num_parents += ((nodes_remaining % ITREE_MAX_NODES) > 0);
131 
132  /*
133  * each parent is composed by merging four adjacent children
134  * this generates a useful index structure in O(n) time
135  * because the edges are from a ring, and thus are
136  * spatially autocorrelated, so the pre-sorting step of
137  * building a packed index is already done for us before we even start
138  */
139  for (uint32_t i = 0; i < num_parents; i++)
140  {
141  uint32_t children_start = start_node + i * ITREE_MAX_NODES;
142  uint32_t children_end = start_node + (i+1) * ITREE_MAX_NODES;
143  children_end = children_end > end_node ? end_node : children_end;
144 
145  /*
146  * put pointers to the children we are merging onto
147  * the new parent node
148  */
149  IntervalTreeNode *parent_node = itree_new_node(itree);
150  for (uint32_t j = children_start; j < children_end; j++)
151  {
152  IntervalTreeNode *child_node = &(itree->nodes[j]);
153  parent_node->min = FP_MIN(child_node->min, parent_node->min);
154  parent_node->max = FP_MAX(child_node->max, parent_node->max);
155  parent_node->edgeIndex = FP_MIN(child_node->edgeIndex, parent_node->edgeIndex);
156  parent_node->children[parent_node->numChildren++] = child_node;
157  }
158  }
159 
160  /*
161  * keep going until num_parents gets down to one and
162  * we are at the root of the tree
163  */
164  return num_parents;
165 }
static IntervalTreeNode * itree_new_node(IntervalTree *itree)
Definition: intervaltree.c:99
#define ITREE_MAX_NODES
Definition: intervaltree.h:29
#define FP_MAX(A, B)
#define FP_MIN(A, B)
struct IntervalTreeNode * children[ITREE_MAX_NODES]
Definition: intervaltree.h:43
uint32_t edgeIndex
Definition: intervaltree.h:44
uint32_t numChildren
Definition: intervaltree.h:45
struct IntervalTreeNode * nodes
Definition: intervaltree.h:58
uint32_t numNodes
Definition: intervaltree.h:64

References IntervalTreeNode::children, IntervalTreeNode::edgeIndex, FP_MAX, FP_MIN, ITREE_MAX_NODES, itree_new_node(), IntervalTreeNode::max, IntervalTreeNode::min, IntervalTree::nodes, IntervalTreeNode::numChildren, and IntervalTree::numNodes.

Referenced by itree_add_pointarray().

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