Example #1
0
void test_array(void)
{
	tommy_array array;
	unsigned i;

	tommy_array_init(&array);

	START("array init");
	for(i=0;i<MAX*100;++i) {
		tommy_array_grow(&array, i + 1);
		if (tommy_array_get(&array, i) != 0)
			abort();
	}
	STOP();

	START("array set");
	for(i=0;i<MAX*100;++i) {
		tommy_array_set(&array, i, (void*)i);
	}
	STOP();

	START("array get");
	for(i=0;i<MAX*100;++i) {
		if (tommy_array_get(&array, i) != (void*)i)
			abort();
	}
	STOP();

	tommy_array_done(&array);
}
Example #2
0
cr_cache_t *crcache_init (void) {
  cr_cache_t *cache;
  tommy_array *array;

  cache = calloc (1,sizeof (cr_cache_t));
  array = calloc (1,sizeof (tommy_array));

  tommy_array_init (array);

  cache->crates = array;
  cache->alloc_exp = TOMMY_ARRAY_BIT;
  cache->read = crcache_read;
  cache->write = crcache_write;
  cache->free = crcache_free;

  tommy_array_grow (cache->crates,pow (2,cache->alloc_exp));

  return cache;
}
Example #3
0
static void test_tommy(void)
{
	tommy_array array;
	tommy_arrayblk arrayblk;
	tommy_arrayblkof arrayblkof;
	tommy_hashdyn hashdyn;
	tommy_hashdyn_node node[TOMMY_SIZE];
	unsigned i;

	tommy_array_init(&array);
	tommy_arrayblk_init(&arrayblk);
	tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned));

	for(i=0;i<TOMMY_SIZE;++i) {
		tommy_array_insert(&array, &node[i]);
		tommy_arrayblk_insert(&arrayblk, &node[i]);
		tommy_arrayblkof_grow(&arrayblkof, i + 1);
		*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i;
	}

	if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*))
		goto bail;
	if (tommy_arrayblk_memory_usage(&arrayblk) < TOMMY_SIZE * sizeof(void*))
		goto bail;
	if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned))
		goto bail;

	for(i=0;i<TOMMY_SIZE;++i) {
		if (tommy_array_get(&array, i) != &node[i])
			goto bail;
		if (tommy_arrayblk_get(&arrayblk, i) != &node[i])
			goto bail;
		if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i)
			goto bail;
	}

	tommy_arrayblkof_done(&arrayblkof);
	tommy_arrayblk_done(&arrayblk);
	tommy_array_done(&array);

	tommy_hashdyn_init(&hashdyn);

	for(i=0;i<TOMMY_SIZE;++i)
		tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64);

	if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE)
		goto bail;

	if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(void*))
		goto bail;

	for(i=0;i<TOMMY_SIZE/2;++i)
		tommy_hashdyn_remove_existing(&hashdyn, &node[i]);

	for(i=0;i<TOMMY_SIZE/2;++i)
		if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0)
			goto bail;

	for(i=TOMMY_SIZE/2;i<TOMMY_SIZE;++i)
		if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0)
			goto bail;

	if (tommy_hashdyn_count(&hashdyn) != 0)
		goto bail;

	tommy_hashdyn_done(&hashdyn);

	return;
bail:
	/* LCOV_EXCL_START */
	fprintf(stderr, "Failed tommy test\n");
	exit(EXIT_FAILURE);
	/* LCOV_EXCL_STOP */
}
Example #4
0
void tommy_arrayblk_init(tommy_arrayblk* array)
{
	tommy_array_init(&array->block);

	array->size = 0;
}