コード例 #1
0
/** 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);
}
コード例 #2
0
ファイル: testlruhash.c プロジェクト: inter-rpm/dplus-c
//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);
}
コード例 #3
0
/** test adding a random element */
static void
testlookup(struct lruhash* table, testdata_t* ref[])
{
	int num = random() % HASHTESTMAX;
	testkey_t* key = newkey(num);
	struct lruhash_entry* en = lruhash_lookup(table, myhash(num), key, 0);
	testdata_t* data = en? (testdata_t*)en->data : NULL;
	if(en) {
		unit_assert(en->key);
		unit_assert(en->data);
	}
	if(0) log_info("lookup %d got %d, expect %d", num, en? data->data :-1,
		ref[num]? ref[num]->data : -1);
	unit_assert( data == ref[num] );
	if(en) { lock_rw_unlock(&en->lock); }
	delkey(key);
}
コード例 #4
0
ファイル: testlruhash.c プロジェクト: inter-rpm/dplus-c
//test lookup a random element
static void testlookup(struct lruhash *table, testdata *ref[])
{
    int num = random() % MAXHASH;
    testkey *key = newkey(num);
    struct lruhash_entry *e = lruhash_lookup(table, simplehash(num), key);
    testdata *data = e ? (testdata *)e->data : NULL;

    if(e) {
        unit_assert(e->key);
        unit_assert(e->data);
        lock_basic_unlock(&e->lock);
    }
    if (ref)
        unit_assert(data == ref[num]);

    delkey(key);
}
コード例 #5
0
/** test adding a random element (unlimited range) */
static void
testlookup_unlim(struct lruhash* table, testdata_t** ref)
{
	int num = random() % (HASHTESTMAX*10);
	testkey_t* key = newkey(num);
	struct lruhash_entry* en = lruhash_lookup(table, myhash(num), key, 0);
	testdata_t* data = en? (testdata_t*)en->data : NULL;
	if(en) {
		unit_assert(en->key);
		unit_assert(en->data);
	}
	if(0 && ref) log_info("lookup unlim %d got %d, expect %d", num, en ? 
		data->data :-1, ref[num] ? ref[num]->data : -1);
	if(data && ref) {
		/* its okay for !data, it fell off the lru */
		unit_assert( data == ref[num] );
	}
	if(en) { lock_rw_unlock(&en->lock); }
	delkey(key);
}
コード例 #6
0
ファイル: slabhash.c プロジェクト: FreeBSDFoundation/freebsd
struct lruhash_entry* slabhash_lookup(struct slabhash* sl, 
	hashvalue_type hash, void* key, int wr)
{
	return lruhash_lookup(sl->array[slab_idx(sl, hash)], hash, key, wr);
}