static HashTable * create_pixel_hash(Pixel *pixelData,uint32_t nPixels) { PixelHashData *d; HashTable *hash; uint32_t i; #ifndef NO_OUTPUT uint32_t timer,timer2,timer3; #endif /* malloc check ok, small constant allocation */ d=malloc(sizeof(PixelHashData)); if (!d) return NULL; hash=hashtable_new(pixel_hash,pixel_cmp); hashtable_set_user_data(hash,d); d->scale=0; #ifndef NO_OUTPUT timer=timer3=clock(); #endif for (i=0;i<nPixels;i++) { if (!hashtable_insert_or_update_computed(hash, pixelData[i], new_count_func, exists_count_func)) {; } while (hashtable_get_count(hash)>MAX_HASH_ENTRIES) { d->scale++; #ifndef NO_OUTPUT printf ("rehashing - new scale: %d\n",(int)d->scale); timer2=clock(); #endif hashtable_rehash_compute(hash,rehash_collide); #ifndef NO_OUTPUT timer2=clock()-timer2; printf ("rehash took %f sec\n",timer2/(double)CLOCKS_PER_SEC); timer+=timer2; #endif } } #ifndef NO_OUTPUT printf ("inserts took %f sec\n",(clock()-timer)/(double)CLOCKS_PER_SEC); #endif #ifndef NO_OUTPUT printf ("total %f sec\n",(clock()-timer3)/(double)CLOCKS_PER_SEC); #endif return hash; }
static HashTable create_pixel_hash(Pixel *pixelData,unsigned long nPixels) { PixelHashData *d; HashTable *hash; unsigned long i; unsigned long timer,timer2,timer3; d=malloc(sizeof(PixelHashData)); if (!d) return NULL; hash=hashtable_new(pixel_hash,pixel_cmp); hashtable_set_user_data(hash,d); d->scale=0; timer=timer3=clock(); for (i=0;i<nPixels;i++) { if (!hashtable_insert_or_update_computed(hash, (void *)pixelData[i].v, new_count_func, exists_count_func)) {; } while (hashtable_get_count(hash)>MAX_HASH_ENTRIES) { d->scale++; #ifndef NO_OUTPUT printf ("rehashing - new scale: %d\n",(int)d->scale); #endif timer2=clock(); hashtable_rehash_compute(hash,rehash_collide); timer2=clock()-timer2; #ifndef NO_OUTPUT printf ("rehash took %f sec\n",timer2/(double)CLOCKS_PER_SEC); #endif timer+=timer2; } } #ifndef NO_OUTPUT printf ("inserts took %f sec\n",(clock()-timer)/(double)CLOCKS_PER_SEC); #endif #ifndef NO_OUTPUT printf ("total %f sec\n",(clock()-timer3)/(double)CLOCKS_PER_SEC); #endif return hash; }