/** test adding a random element */
static void
testadd(struct lruhash* table, testdata_t* ref[])
{
	int numtoadd = random() % HASHTESTMAX;
	testdata_t* data = newdata(numtoadd);
	testkey_t* key = newkey(numtoadd);
	key->entry.data = data;
	lruhash_insert(table, myhash(numtoadd), &key->entry, data, NULL);
	ref[numtoadd] = data;
}
Exemple #2
0
//test add a random element
static void testadd(struct lruhash *table, testdata *ref[])
{
    int num = random() % MAXHASH;
    testdata *data = newdata(num);
    testkey *key = newkey(num);
    key->entry.data = data;
    lruhash_insert(table, simplehash(num), &key->entry, data);
    if(ref)
        ref[num] = data;
}
/** test adding a random element (unlimited range) */
static void
testadd_unlim(struct lruhash* table, testdata_t** ref)
{
	int numtoadd = random() % (HASHTESTMAX * 10);
	testdata_t* data = newdata(numtoadd);
	testkey_t* key = newkey(numtoadd);
	key->entry.data = data;
	lruhash_insert(table, myhash(numtoadd), &key->entry, data, NULL);
	if(ref)
		ref[numtoadd] = data;
}
/** test hashtable using short sequence */
static void
test_short_table(struct lruhash* table) 
{
	testkey_t* k = newkey(12);
	testkey_t* k2 = newkey(14);
	testdata_t* d = newdata(128);
	testdata_t* d2 = newdata(129);
	
	k->entry.data = d;
	k2->entry.data = d2;

	lruhash_insert(table, myhash(12), &k->entry, d, NULL);
	lruhash_insert(table, myhash(14), &k2->entry, d2, NULL);
	
	unit_assert( lruhash_lookup(table, myhash(12), k, 0) == &k->entry);
	lock_rw_unlock( &k->entry.lock );
	unit_assert( lruhash_lookup(table, myhash(14), k2, 0) == &k2->entry);
	lock_rw_unlock( &k2->entry.lock );
	lruhash_remove(table, myhash(12), k);
	lruhash_remove(table, myhash(14), k2);
}
Exemple #5
0
//test lruhash_insert, lruhash_lookup and lruhash_remove
static void test_short_table(struct lruhash *table)
{
    testkey *k1 = newkey(12);
    testkey *k2 = newkey(14);
    testdata *d1 = newdata(128);
    testdata *d2 = newdata(129);

    k1->entry.data = d1;
    k2->entry.data = d2;

    lruhash_insert(table, simplehash(12), &k1->entry, d1);
    lruhash_insert(table, simplehash(14), &k2->entry, d2);

    unit_assert(lruhash_lookup(table, simplehash(12), k1) == &k1->entry);
    lock_basic_unlock(&k1->entry.lock);

    unit_assert(lruhash_lookup(table, simplehash(14), k2) == &k2->entry);
    lock_basic_unlock(&k2->entry.lock );

    lruhash_remove(table, simplehash(12), k1);
    lruhash_remove(table, simplehash(14), k2);
}
Exemple #6
0
void slabhash_insert(struct slabhash* sl, hashvalue_type hash, 
	struct lruhash_entry* entry, void* data, void* arg)
{
	lruhash_insert(sl->array[slab_idx(sl, hash)], hash, entry, data, arg);
}