PostGIS  2.2.7dev-r@@SVN_REVISION@@
static void test_unionfind_union ( void  )
static

Definition at line 33 of file cu_unionfind.c.

References UNIONFIND::cluster_sizes, UNIONFIND::clusters, UNIONFIND::N, UNIONFIND::num_clusters, UF_create(), UF_destroy(), and UF_union().

Referenced by unionfind_suite_setup().

34 {
35  UNIONFIND *uf = UF_create(10);
36 
37  UF_union(uf, 0, 7); /* both have size = 1, so 7 becomes 0 */
38  UF_union(uf, 3, 2); /* both have size = 1, so 3 becomes 2 */
39  UF_union(uf, 8, 7); /* add 8 (smaller) to 0-7 (larger) */
40  UF_union(uf, 1, 2); /* add 1 (smaller) to 2-3 (larger) */
41 
42  uint32_t expected_final_ids[] = { 0, 2, 2, 2, 4, 5, 6, 0, 0, 9 };
43  uint32_t expected_final_sizes[] = { 3, 0, 3, 0, 1, 1, 1, 0, 0, 1 };
44 
45  CU_ASSERT_EQUAL(10, uf->N);
46  CU_ASSERT_EQUAL(6, uf->num_clusters);
47  CU_ASSERT_EQUAL(0, memcmp(uf->clusters, expected_final_ids, 10*sizeof(uint32_t)));
48  CU_ASSERT_EQUAL(0, memcmp(uf->cluster_sizes, expected_final_sizes, 10*sizeof(uint32_t)));
49 
50  UF_destroy(uf);
51 }
void UF_destroy(UNIONFIND *uf)
Definition: lwunionfind.c:40
uint32_t * clusters
Definition: lwunionfind.h:20
uint32_t * cluster_sizes
Definition: lwunionfind.h:21
uint32_t N
Definition: lwunionfind.h:23
uint32_t num_clusters
Definition: lwunionfind.h:22
UNIONFIND * UF_create(uint32_t N)
Definition: lwunionfind.c:21
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)
Definition: lwunionfind.c:65

Here is the call graph for this function:

Here is the caller graph for this function: