示例#1
0
static int
time_it(cfuhash_function_t hf, double *elapsed_time, u_int32_t num_tests) {
	cfuhash_table_t *hash = cfuhash_new_with_initial_size(30);
	u_int32_t flags = 0;
	char key[32];
	char value[32];
	size_t i;
	size_t used;
	size_t num_buckets;
	size_t num_entries;
	cfutime_t *time = cfutime_new();

	/* freeze the hash so that it won't shrink while we put in all the data */
	flags = cfuhash_set_flag(hash, CFUHASH_FROZEN_UNTIL_GROWS);
	cfuhash_set_hash_function(hash, hf);

	cfutime_begin(time);
	for (i = 0; i < num_tests; i++) {
		sprintf(key, "%u", 15000000 - i);
		sprintf(value, "value%d", i);
		cfuhash_put(hash, key, dup_str(value));
	}
	cfutime_end(time);
	*elapsed_time = cfutime_elapsed(time);

	used = cfuhash_num_buckets_used(hash);
	num_buckets = cfuhash_num_buckets(hash);
	num_entries = cfuhash_num_entries(hash);
	printf("%d entries, %d/%d buckets (%.2f%%), %.2f%% threshold check\n", num_entries, used, num_buckets, 100.0 * (float)used/(float)num_buckets, 100.0 * (float)num_entries/(float)num_buckets);

	cfuhash_destroy_with_free_fn(hash, free_data);	

	return 0;
}
示例#2
0
void bt_destroy_device_table(void) {
	if (bt_devices_table) {
		cfuhash_destroy_with_free_fn(bt_devices_table, free);
	}
	bt_devices_table = NULL;
}