Beispiel #1
0
void
stress_test_ht(int amt)
{
	ht t;
	int i;
	gendata x, y;

	/* Just take a modulo somewhere around amt/4. */
	t = ht_create((unsigned int)(amt / 4.0), num_hash);
	assert(ht_empty(t));

	printf("Creating a hash table with %d items...\n", amt);
	for (i = 0; i < amt; ++i) {
		x.num = y.num = i;
		t = ht_insert_uniq(t, x, y, num_eq);

		assert(!ht_empty(t));

		ht_lookup(t, x, num_eq, &y);
		assert(x.num == y.num);
	}

	y.ptr = NULL;
	printf("Walking a hash table of %d items...\n", amt);
	ht_walk(t, walker, y);

	printf("Deleting %d items from the hash table...\n", amt);
	for (i = 0; i < amt; ++i) {
		/* Inserting an item that's already there should fail */
		x.num = i;
		y.num = i;			/* Value does not matter */
		assert(ht_insert_uniq(t, x, y, num_eq) == NULL);

		t = ht_delete(t, x, num_eq, NULL, NULL);
	}
	assert(ht_empty(t));
	ht_destroy(t, NULL, NULL);
}
Beispiel #2
0
void *ht_pop(hashtable *ht, void **key, void **data)
{
    size_t i;

    if (!ht || !key || !data)
        return NULL;

    if (ht_empty(ht))
        return NULL;

    for (i = 0; i < ht->n_buckets; i++)
    {
        if (!htbucket_empty(ht->buckets + i))
            return htbucket_pop(ht->buckets + i, key, data);
    }
    return NULL;
}