Ejemplo n.º 1
0
static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
                             list_t *list)
{
    if(bucket_is_empty(hashtable, bucket))
    {
        list_insert(&hashtable->list, list);
        bucket->first = bucket->last = list;
    }
    else
    {
        list_insert(bucket->first, list);
        bucket->first = list;
    }
}
Ejemplo n.º 2
0
/*
 * heap_ensure_bucket_filled -- (internal) refills the bucket if needed
 */
static void
heap_ensure_bucket_filled(PMEMobjpool *pop, struct bucket *b, int force)
{
	if (!force && !bucket_is_empty(b))
		return;

	if (!bucket_is_small(b)) {
		/* not much to do here apart from using the next zone */
		heap_populate_buckets(pop);
		return;
	}

	struct bucket *def_bucket = heap_get_default_bucket(pop);

	struct memory_block m = {0, 0, 1, 0};
	if (heap_get_bestfit_block(pop, def_bucket, &m) != 0)
		return; /* OOM */

	ASSERT(m.block_off == 0);

	heap_populate_run_bucket(pop, b, m.chunk_id, m.zone_id);
}
Ejemplo n.º 3
0
static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
                                   const char *key, size_t hash)
{
    list_t *list;
    pair_t *pair;

    if(bucket_is_empty(hashtable, bucket))
        return NULL;

    list = bucket->first;
    while(1)
    {
        pair = list_to_pair(list);
        if(pair->hash == hash && strcmp(pair->key, key) == 0)
            return pair;

        if(list == bucket->last)
            break;

        list = list->next;
    }

    return NULL;
}
Ejemplo n.º 4
0
static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
                                   const void *key, unsigned int hash)
{
    list_t *list;
    pair_t *pair;

    if(bucket_is_empty(hashtable, bucket))
        return NULL;

    list = bucket->first;
    while(1)
    {
        pair = list_to_pair(list);
        if(pair->hash == hash && hashtable->cmp_keys(pair->key, key))
            return pair;

        if(list == bucket->last)
            break;

        list = list->next;
    }

    return NULL;
}