PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ UF_ordered_by_cluster()

uint32_t* UF_ordered_by_cluster ( UNIONFIND uf)

Definition at line 113 of file lwunionfind.c.

114 {
115  size_t i;
116  uint32_t** cluster_id_ptr_by_elem_id = lwalloc(uf->N * sizeof (uint32_t*));
117  uint32_t* ordered_ids = lwalloc(uf->N * sizeof (uint32_t));
118 
119  for (i = 0; i < uf->N; i++)
120  {
121  /* Make sure each value in uf->clusters is pointing to the
122  * root of the cluster.
123  * */
124  UF_find(uf, i);
125  cluster_id_ptr_by_elem_id[i] = &(uf->clusters[i]);
126  }
127 
128  /* Sort the array of cluster id pointers, so that pointers to the
129  * same cluster id are grouped together.
130  * */
131  qsort(cluster_id_ptr_by_elem_id, uf->N, sizeof (uint32_t*), &cmp_int_ptr);
132 
133  /* Recover the input element ids from the cluster id pointers, so
134  * we can return element ids grouped by cluster id.
135  * */
136  for (i = 0; i < uf-> N; i++)
137  {
138  ordered_ids[i] = (cluster_id_ptr_by_elem_id[i] - uf->clusters);
139  }
140 
141  lwfree(cluster_id_ptr_by_elem_id);
142  return ordered_ids;
143 }
void lwfree(void *mem)
Definition: lwutil.c:242
void * lwalloc(size_t size)
Definition: lwutil.c:227
static int cmp_int_ptr(const void *a, const void *b)
Definition: lwunionfind.c:197
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
Definition: lwunionfind.c:62
uint32_t N
Definition: lwunionfind.h:36
uint32_t * clusters
Definition: lwunionfind.h:33

References UNIONFIND::clusters, cmp_int_ptr(), lwalloc(), lwfree(), UNIONFIND::N, and UF_find().

Referenced by combine_geometries(), test_unionfind_ordered_by_cluster(), and UF_get_collapsed_cluster_ids().

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