Esempio n. 1
0
GhtErr
ght_node_count_leaves(const GhtNode *node, int *count)
{
	int i;
	GhtErr err;

	/* No-op on empty */
	if ( ! node ) return GHT_OK;

	if ( ght_node_is_leaf(node) )
	{
		*count += 1;
		return GHT_OK;
	}
	for ( i = 0; i < ght_node_num_children(node); i++ )
	{
		GHT_TRY(ght_node_count_leaves(node->children->nodes[i], count));
	}
	return GHT_OK;
}
Esempio n. 2
0
static void
test_ght_node_build_tree_big(void)
{
    GhtCoordinate coord;
    int i, j;
    int npts = 200;
    const double x_off = -127.0;
    const double y_off = 49.0;
    const double scale = 0.0001;
    GhtNode *node, *root;
    GhtErr err;
    int count = 0;
    stringbuffer_t *sb;

    for ( i = 0; i < npts; i++ )
    {
        for ( j = 0; j < npts; j++ )
        {
            coord.x = x_off + i*scale;
            coord.y = y_off + j*scale;
            err = ght_node_new_from_coordinate(&coord, GHT_MAX_HASH_LENGTH, &node);
            if ( i || j )
            {
                err = ght_node_insert_node(root, node, GHT_DUPES_YES);
            }
            else
            {
                root = node;
            }
        }
    }
    // sb = stringbuffer_create();
    // err = ght_node_to_string(root, sb, 0);
    // printf("\n%s\n", stringbuffer_getstring(sb));
    // stringbuffer_destroy(sb);
    err = ght_node_count_leaves(root, &count);
    CU_ASSERT_EQUAL(err, GHT_OK);
    // printf("count %d\n", count);
    CU_ASSERT_EQUAL(count, npts*npts);
    ght_node_free(root);
}