31 static int cmp_int(
const void *a,
const void *b);
32 static int cmp_int_ptr(
const void *a,
const void *b);
44 for (i = 0; i < N; 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));
119 for (i = 0; i < uf->
N; i++)
125 cluster_id_ptr_by_elem_id[i] = &(uf->
clusters[i]);
131 qsort(cluster_id_ptr_by_elem_id, uf->
N, sizeof (uint32_t*), &
cmp_int_ptr);
136 for (i = 0; i < uf-> N; i++)
138 ordered_ids[i] = (cluster_id_ptr_by_elem_id[i] - uf->
clusters);
141 lwfree(cluster_id_ptr_by_elem_id);
149 uint32_t* new_ids =
lwalloc(uf->
N *
sizeof(uint32_t));
150 uint32_t last_old_id, current_new_id, i;
151 char encountered_cluster =
LW_FALSE;
153 current_new_id = 0; last_old_id = 0;
154 for (i = 0; i < uf->
N; i++)
156 uint32_t j = ordered_components[i];
157 if (!is_in_cluster || is_in_cluster[j])
159 uint32_t current_old_id =
UF_find(uf, j);
160 if (!encountered_cluster)
163 last_old_id = current_old_id;
166 if (current_old_id != last_old_id)
169 new_ids[j] = current_new_id;
170 last_old_id = current_old_id;
174 lwfree(ordered_components);
182 if (*((uint32_t*) a) > *((uint32_t*) b))
186 else if (*((uint32_t*) a) < *((uint32_t*) b))
199 int val_cmp =
cmp_int(*((uint32_t**) a), *((uint32_t**) b));
void * lwalloc(size_t size)
#define LW_TRUE
Return types for functions with status returns.
This library is the generic geometry handling section of PostGIS.
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)
void UF_destroy(UNIONFIND *uf)
static int cmp_int_ptr(const void *a, const void *b)
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
uint32_t UF_size(UNIONFIND *uf, uint32_t i)
static int cmp_int(const void *a, const void *b)
UNIONFIND * UF_create(uint32_t N)
uint32_t * UF_ordered_by_cluster(UNIONFIND *uf)
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)