PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ UF_get_collapsed_cluster_ids()

uint32_t* UF_get_collapsed_cluster_ids ( UNIONFIND uf,
const char *  is_in_cluster 
)

Definition at line 145 of file lwunionfind.c.

References LW_FALSE, LW_TRUE, lwalloc(), lwfree(), UNIONFIND::N, UF_find(), and UF_ordered_by_cluster().

Referenced by do_dbscan_test(), ST_ClusterDBSCAN(), and test_unionfind_collapse_cluster_ids().

146 {
147  uint32_t* ordered_components = UF_ordered_by_cluster(uf);
148  uint32_t* new_ids = lwalloc(uf->N * sizeof(uint32_t));
149  uint32_t last_old_id, current_new_id, i;
150  char encountered_cluster = LW_FALSE;
151 
152  current_new_id = 0;
153  for (i = 0; i < uf->N; i++)
154  {
155  uint32_t j = ordered_components[i];
156  if (!is_in_cluster || is_in_cluster[j])
157  {
158  uint32_t current_old_id = UF_find(uf, j);
159  if (!encountered_cluster)
160  {
161  encountered_cluster = LW_TRUE;
162  last_old_id = current_old_id;
163  }
164 
165  if (current_old_id != last_old_id)
166  current_new_id++;
167 
168  new_ids[j] = current_new_id;
169  last_old_id = current_old_id;
170  }
171  }
172 
173  lwfree(ordered_components);
174 
175  return new_ids;
176 }
void lwfree(void *mem)
Definition: lwutil.c:242
uint32_t N
Definition: lwunionfind.h:36
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
Definition: lwunionfind.c:61
#define LW_FALSE
Definition: liblwgeom.h:76
uint32_t * UF_ordered_by_cluster(UNIONFIND *uf)
Definition: lwunionfind.c:112
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
void * lwalloc(size_t size)
Definition: lwutil.c:227
Here is the call graph for this function:
Here is the caller graph for this function: