Пример #1
0
END_TEST

START_TEST(eina_rbtree_lookup)
{
   Eina_Rbtree_Int *root = NULL;
   Eina_Rbtree_Int *item;
   int list[] = { 50, 100, 10, 43, 23 };
   unsigned int i;

   for (i = 0; i < sizeof (list) / sizeof (int); ++i)
     {
        item = _eina_rbtree_int_new(list[i]);
        root = (Eina_Rbtree_Int *)eina_rbtree_inline_insert(
              &root->node,
              &item->node,
                             EINA_RBTREE_CMP_NODE_CB(
                 eina_rbtree_int_cmp),
              NULL);
     }

   item = (Eina_Rbtree_Int *)eina_rbtree_inline_lookup(&root->node,
                                                       &list[0],
                                                       sizeof(int),
                                                       EINA_RBTREE_CMP_KEY_CB(
                                                          eina_rbtree_int_key),
                                                       NULL);
   fail_if(!item);

   i = 42;
   item =
      (Eina_Rbtree_Int *)eina_rbtree_inline_lookup(&root->node,
                                                   &i,
                                                   sizeof(int),
                                                   EINA_RBTREE_CMP_KEY_CB(
                                                      eina_rbtree_int_key),
                                                   NULL);
   fail_if(item);
}
Пример #2
0
static void
eina_bench_lookup_rbtree(int request)
{
   Eina_Rbtree *root = NULL;
   int i;
   int j;

   for (i = 0; i < request; ++i)
     {
        Eina_Bench_Rbtree *tmp;

        tmp = malloc(sizeof (Eina_Bench_Rbtree));
        if (!tmp)
           continue;

        tmp->value = i;
        eina_convert_itoa(i, tmp->key);

        root = eina_rbtree_inline_insert(root,
                                         &tmp->node,
                                         EINA_RBTREE_CMP_NODE_CB(
                                            _eina_bench_rbtree_cmp),
                                         NULL);
     }

   srand(time(NULL));

   for (j = 0; j < 200; ++j)
      for (i = 0; i < request; ++i)
        {
           Eina_Rbtree *tmp;
           char tmp_key[10];

           eina_convert_itoa(rand() % request, tmp_key);

           tmp = eina_rbtree_inline_lookup(root,
                                           tmp_key,
                                           10,
                                           EINA_RBTREE_CMP_KEY_CB(
                                              _eina_bench_rbtree_key),
                                           NULL);
           /* Suppress warnings as we really don't want to do anything. */
           (void) tmp;
        }

   eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL);
}
Пример #3
0
int main()
{
	const intptr_t max = 10000000;
	intptr_t i;
	struct timeval g_start, start, end, diff;
	test_rbtree_node_t *trn;
	test_rbtree_fast_node_t *trfn;
	gds_inline_rbtree_node_t *irn;
	gds_inline_rbtree_fast_node_t *irfn;

	/* gds_inline_rbtree */
	printf("gds_inline_rbtree\n");
	gettimeofday(&g_start, NULL);
	printf("\tInserting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	gds_inline_rbtree_node_t *root = NULL;
	for(i=0; i<max; i++) {
		trn = trn_new(i);
		gds_inline_rbtree_add(&root, &(trn->rbtree), trn_cmp, NULL);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tGetting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	for(i=0; i<max; i++) {
		gds_inline_rbtree_get_node(root, &i, trn_cmp_with_key, NULL);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tDeleting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	for(i=0; i<max; i++) {
		irn = gds_inline_rbtree_del(&root, &i, trn_cmp_with_key, NULL);
		trn = trn_container_of(irn);
		trn_free(trn);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	timeval_diff(&g_start, &end, &diff);
	printf("\tTotal time: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tEstimated size: %ld bytes\n", max * (sizeof(test_rbtree_node_t)));

	/* gds_inline_rbtree_fast */
	printf("gds_inline_rbtree_fast\n");
	gettimeofday(&g_start, NULL);
	printf("\tInserting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	gds_inline_rbtree_fast_node_t *froot = NULL;
	for(i=0; i<max; i++) {
		trfn = trfn_new(i);
		gds_inline_rbtree_fast_add(&froot, &(trfn->rbtree), trfn_cmp, NULL);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tGetting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	for(i=0; i<max; i++) {
		gds_inline_rbtree_fast_get_node(froot, &i, trfn_cmp_with_key, NULL);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tDeleting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	for(i=0; i<max; i++) {
		irfn = gds_inline_rbtree_fast_del(&froot, &i, trfn_cmp_with_key, NULL);
		trfn = trfn_container_of(irfn);
		trfn_free(trfn);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	timeval_diff(&g_start, &end, &diff);
	printf("\tTotal time: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tEstimated size: %ld bytes\n", max * (sizeof(test_rbtree_fast_node_t)));
	
	/* eina */
	printf("eina\n");
	gettimeofday(&g_start, NULL);
	printf("\tInserting %ld nodes\n", max);
	gettimeofday(&start, NULL);
	Eina_Rbtree *eroot = NULL;
	test_eina_rbtree_node_t *tern;
	for(i=0; i<max; i++) {
		tern = tern_new(i);
		eroot = eina_rbtree_inline_insert(eroot, EINA_RBTREE_GET(tern), EINA_RBTREE_CMP_NODE_CB(tern_cmp), NULL);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tGetting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	Eina_Rbtree *n = NULL;
	for(i=0; i<max; i++) {
		n = eina_rbtree_inline_lookup(eroot, &i, 1, EINA_RBTREE_CMP_KEY_CB(tern_cmpkey), NULL);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tDeleting %ld nodes...\n", max);
	gettimeofday(&start, NULL);
	for(i=0; i<max; i++) {
		n = eina_rbtree_inline_lookup(eroot, &i, 1, EINA_RBTREE_CMP_KEY_CB(tern_cmpkey), NULL);
		eroot = eina_rbtree_inline_remove(eroot, n, EINA_RBTREE_CMP_NODE_CB(tern_cmp), NULL);
		tern = EINA_RBTREE_CONTAINER_GET(n, test_eina_rbtree_node_t);
		free(tern);
	}
	gettimeofday(&end, NULL);
	timeval_diff(&start, &end, &diff);
	printf("\tTime: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	timeval_diff(&g_start, &end, &diff);
	printf("\tTotal time: %lds %ldus\n", diff.tv_sec, diff.tv_usec);
	printf("\tEstimated size: %ld bytes\n", max * (sizeof(test_eina_rbtree_node_t)));

	return 0;
}