Esempio n. 1
0
HashTableIterator hash_itr_next(HashTableIterator itr)
{
    if (!itr) 
        return 0;
    
    itr->list_itr = list_itr_next(itr->list_itr);
    if(itr->list_itr)
    {
        return itr;   
    }
    else if(itr->index >= itr->hashtable->size-1)   
    {
        itr->list_itr = 0;
        itr->index = 0;
        itr->hashtable = 0;   
        return 0;
    }
    else
    {
        while((++itr->index < itr->hashtable->size) && list_empty(&itr->hashtable->hashbucket[itr->index].list)); 
        if (itr->index >= itr->hashtable->size)
        {
            itr->list_itr = 0;
            itr->index = 0;
            itr->hashtable = 0;   
            return 0;   
        }
        else
        {
            itr->list_itr=list_itr_begin(&itr->hashtable->hashbucket[itr->index].list);
            return itr;
        }
    }
}
Esempio n. 2
0
static void dict_buckets_destroy(Dict dict)
{
    /*  If dict_buckets_create() failed, then the first pointer
     *  in dict->buckets[] corresponding to a failed list
     *  creation is set to NULL. Therefore loop over the total
     *  number of buckets, or until we encounter NULL, whichever
     *  comes first.                                              */

    for ( size_t i = 0; i < dict->num_buckets && dict->buckets[i]; ++i ) {
        ListItr itr = list_itr_first(dict->buckets[i]);
        while ( itr ) {
            struct gds_kvpair * pair;
            list_get_value_itr(itr, &pair);
            gds_kvpair_destroy(pair, dict->free_on_destroy);
            itr = list_itr_next(itr);
        }
        list_destroy(dict->buckets[i]);
    }
}