Esempio n. 1
0
void destroy_screen_context(struct ScreenContext *screenContext)
{
  	region_free_func(screenContext->region);
  	region_free_func(screenContext->vRegion);
	duallist_destroy(&screenContext->roads, NULL);
	duallist_destroy(&screenContext->crosses, NULL);
	duallist_destroy(&screenContext->links, NULL);
	duallist_destroy(&screenContext->rsus, NULL);
	duallist_destroy(&screenContext->districts, NULL);
	duallist_destroy(&screenContext->rivers, NULL);
	duallist_destroy(&screenContext->surroundings, NULL);
	hashtable_destroy(&screenContext->routeTable, (void(*)(void*))route_free_func);
	duallist_destroy(&screenContext->selectedRoutes, NULL);
	hashtable_destroy(&screenContext->nodeTable, (void(*)(void*))node_free_func);
	hashtable_destroy(&screenContext->traceTable, (void(*)(void*))trace_free_func);
	duallist_destroy(&screenContext->selectedTraces, NULL);
	if(screenContext->contactTableMode == PAIRWISE_TABLE)
		hashtable_destroy(&screenContext->contactTable, (void(*)(void*))pair_free_func);
	else
		hashtable_destroy(&screenContext->contactTable, (void(*)(void*))ego_free_func);
	duallist_destroy(&screenContext->selected, NULL);
	hashtable_destroy(&screenContext->cellTable, NULL);
	free_colormap(screenContext->colormap);

  	gdk_gc_unref(screenContext->gc);
	if(screenContext->canvas) {
		g_object_unref(screenContext->canvas);
		cairo_destroy(screenContext->cr_on_canvas);
		cairo_destroy(screenContext->cr_on_screen);
	}
  	if(screenContext->timeout != 0) 
		gtk_timeout_remove(screenContext->timeout);  
	free(screenContext);
}
Esempio n. 2
0
static void object_del(Object *obj) {
  locker_start1(&obj->lock);
  object_set_collector(obj, NULL);
  assert(hashtable_size(obj->links) == 0);  // make *sure* there are no links
  hashtable_destroy(obj->links);
  obj->magic = 0;
  if (obj->dtor != NULL) {
    obj->dtor(obj->data);
  }
  locker_end();
  free(obj);  // free the memory
  acid_collect_count++;
}
Esempio n. 3
0
/*
 * Try to get the object hash from a manifest file. Caller frees. Returns NULL
 * on failure.
 */
struct file_hash *
manifest_get(struct conf *conf, const char *manifest_path)
{
	int fd;
	gzFile f = NULL;
	struct manifest *mf = NULL;
	struct hashtable *hashed_files = NULL; /* path --> struct file_hash */
	uint32_t i;
	struct file_hash *fh = NULL;

	fd = open(manifest_path, O_RDONLY | O_BINARY);
	if (fd == -1) {
		/* Cache miss. */
		cc_log("No such manifest file");
		goto out;
	}
	f = gzdopen(fd, "rb");
	if (!f) {
		close(fd);
		cc_log("Failed to gzdopen manifest file");
		goto out;
	}
	mf = read_manifest(f);
	if (!mf) {
		cc_log("Error reading manifest file");
		goto out;
	}

	hashed_files = create_hashtable(1000, hash_from_string, strings_equal);

	/* Check newest object first since it's a bit more likely to match. */
	for (i = mf->n_objects; i > 0; i--) {
		if (verify_object(conf, mf, &mf->objects[i - 1], hashed_files)) {
			fh = x_malloc(sizeof(*fh));
			*fh = mf->objects[i - 1].hash;
			goto out;
		}
	}

out:
	if (hashed_files) {
		hashtable_destroy(hashed_files, 1);
	}
	if (f) {
		gzclose(f);
	}
	if (mf) {
		free_manifest(mf);
	}
	return fh;
}
Esempio n. 4
0
void blockstore_exit(struct blockstore *bs) {
  if (bs == NULL) {
    return;
  }

  blockstore_write_headers(bs);

  if (bs->height > 0) {
    Log(LGPFX " closing blockstore w/ height=%d\n", bs->height);
  }

  blockset_close(bs->blockSet);

  hashtable_printstats(bs->hash_blk, "blocks");
  hashtable_clear_with_free(bs->hash_blk);
  hashtable_clear_with_free(bs->hash_orphans);
  hashtable_destroy(bs->hash_blk);
  hashtable_destroy(bs->hash_orphans);

  mutex_free(bs->lock);
  memset(bs, 0, sizeof *bs);
  free(bs);
}
/**
 * free_devtable_info - free device table information.
 *
 * This function frees the path hash table and the name hash tables.
 */
void free_devtable_info(void)
{
	struct hashtable_itr *ph_itr;
	struct path_htbl_element *ph_elt;

	if (!path_htbl)
		return;

	if (hashtable_count(path_htbl) > 0) {
		ph_itr = hashtable_iterator(path_htbl);
		do {
			ph_elt = hashtable_iterator_value(ph_itr);
			/*
			 * Note, since we use the same string for the key and
			 * @name in the name hash table elements, we do not
			 * have to iterate name hash table because @name memory
			 * will be freed when freeing the key.
			 */
			hashtable_destroy(ph_elt->name_htbl, 1);
		} while (hashtable_iterator_advance(ph_itr));
	}
	hashtable_destroy(path_htbl, 1);
}
Esempio n. 6
0
static void /* assumes exclusive access to bucket */
dynstats_destroyCountersIn(dynstats_bucket_t *b, htable *table, dynstats_ctr_t *ctrs) {
	dynstats_ctr_t *ctr;
	int ctrs_purged = 0;
	hashtable_destroy(table, 0);
	while (ctrs != NULL) {
		ctr = ctrs;
		ctrs = ctrs->next;
		dynstats_destroyCtr(ctr);
		ctrs_purged++;
	}
	STATSCOUNTER_ADD(b->ctrMetricsPurged, b->mutCtrMetricsPurged, ctrs_purged);
	ATOMIC_SUB(&b->metricCount, ctrs_purged, &b->mutMetricCount);
}
static void
cleanupRegistry(void *ignored)
{
#ifdef HAVE_PTHREAD
  (void)pthread_mutex_lock(&(s_hash_mutex));
#endif /* HAVE_PTHREAD */
  if (s_hshtbl) {
    hashtable_destroy(s_hshtbl, 0);
    s_hshtbl = NULL;
  }
#ifdef HAVE_PTHREAD
  (void)pthread_mutex_unlock(&(s_hash_mutex));
#endif /* HAVE_PTHREAD */
}
Esempio n. 8
0
void
m2m_destroy(m2m* me /* own. null */) {
    if (!me) return;
    ENSURE(me->base.type == &m2m_t)
    hashtable_destroy(me->employee_by_name);
    m2m_foreach_employee(
						 me,
						 (employee_fun)record_destructor,
						 me);
    array_table_cleanup(&me->employee);
    hashtable_destroy(me->department_by_title);
    m2m_foreach_department(
						   me,
						   (department_fun)record_destructor,
						   me);
    array_table_cleanup(&me->department);
    m2m_foreach_company(
						me,
						(company_fun)record_destructor,
						me);
    array_table_cleanup(&me->company);
    free_memory(me, sizeof(m2m));
}
Esempio n. 9
0
File: txdb.c Progetto: haraldh/bitc
void
txdb_close(struct txdb *txdb)
{
    if (txdb == NULL) {
        return;
    }

    if (txdb->db) {
        leveldb_close(txdb->db);
    }
    leveldb_options_destroy(txdb->db_opts);
    leveldb_readoptions_destroy(txdb->rd_opts);
    leveldb_writeoptions_destroy(txdb->wr_opts);

    hashtable_clear_with_callback(txdb->hash_txo, txdb_hashtable_free_txo_entry);
    hashtable_destroy(txdb->hash_txo);

    hashtable_clear_with_callback(txdb->hash_tx, txdb_hashtable_free_tx_entry);
    hashtable_destroy(txdb->hash_tx);

    free(txdb->path);
    memset(txdb, 0, sizeof *txdb);
    free(txdb);
}
Esempio n. 10
0
int main(void) {
  size_t initcap = 10;
  HashTable *newht, *ht = hashtable_new(initcap);

  if (!ht)
    testfail("Could not create hash table!");

  if (ht->items != 0)
    testfail("New hash table should be empty, instead has size %lu", ht->items);

  hashtable_put(ht, "Elvis", "Presley");
  if (ht->items != 1)
    testfail("Hash table should have size 1 after put instead has size %lu", ht->items);
  expect_to_get(ht, "Elvis", "Presley");

  hashtable_put(ht, "Elvis", "Costello");
  if (ht->items != 1)
    testfail("Hash table should have remained size 1 after put instead has size %lu", ht->items);
  expect_to_get(ht, "Elvis", "Costello");

  hashtable_put(ht, "Janis", "Joplin");
  if (ht->items != 2)
    testfail("Hash table should have grown to size 2 after put instead has size %lu", ht->items);
  expect_to_get(ht, "Janis", "Joplin");

  newht = hashtable_rehash(ht, 100);
  if (newht != ht)
    testfail("Expected hashtable instance to be the same; should not have changed!");

  newht = hashtable_rehash(ht, 0);
  if (newht == ht)
    testfail("Expected hashtable instance to be the different; should have changed!");

  ht = newht;

  if (newht->capacity <= initcap)
    testfail("Expected new hashtable to be larger than %lu, instead got %lu", initcap, newht->capacity);

  if (newht->items != 2)
    testfail("Expected 2 items in new hash table!");

  expect_to_get(ht, "Elvis", "Costello");
  expect_to_get(ht, "Janis", "Joplin");

  hashtable_destroy(ht);

  return 0;
}
Esempio n. 11
0
File: slab.c Progetto: huayl/pelikan
void
slab_teardown(void)
{
    log_info("tear down the %s module", SLAB_MODULE_NAME);

    if (!slab_init) {
        log_warn("%s has never been set up", SLAB_MODULE_NAME);
    }

    hashtable_destroy(hash_table);
    _slab_heapinfo_teardown();
    _slab_slabclass_teardown();
    slab_metrics = NULL;

    slab_init = false;
}
Esempio n. 12
0
void
wallet_close(struct wallet *wallet)
{
   if (wallet == NULL) {
      return;
   }
   bloom_free(wallet->filter);
   wallet->filter = NULL;
   txdb_close(wallet->txdb);
   hashtable_clear_with_callback(wallet->hash_keys, wallet_free_key_cb);
   hashtable_destroy(wallet->hash_keys);
   free(wallet->filename);
   secure_free(wallet->ckey_store);
   memset(wallet, 0, sizeof *wallet);
   free(wallet);
}
Esempio n. 13
0
static inline void /* assumes exclusive access to bucket */
dynstats_destroyCounters(dynstats_bucket_t *b) {
	dynstats_ctr_t *ctr;

    hashtable_destroy(b->table, 0);
	statsobj.DestructAllCounters(b->stats);
	while(1) {
        ctr = b->ctrs;
		if (ctr == NULL) {
			break;
		} else {
            b->ctrs = ctr->next;
			dynstats_destroyCtr(b, ctr, 0);
		}
	}
	STATSCOUNTER_BUMP(b->ctrMetricsPurged, b->mutCtrMetricsPurged, b->metricCount);
}
Esempio n. 14
0
void free_hashtable(void * ht)
{
  int i;
  for (i = 0 ; i < num_metas ; i++)
    if (metas[i].ht == ht)
    {
      metas[i].ht = NULL;     // kbfu
      metas[i].block = NULL;  // kbfu
      hashtable_destroy((struct hashtable*)ht, 0);
      free(metas[i].row_ids); // kbfu
      //if (i != num_metas-1) memmove(&metas[i], &metas[i+1], sizeof(struct hashtable_meta)*(num_metas-i-1));
      //num_metas--;
      //metas = realloc(metas, sizeof(struct hashtable_meta)*num_metas);
      break;
    }
  //if (num_metas == 0) free(metas);
}
Esempio n. 15
0
static void freeGearInfo(gearInfo* gi) {
  if(gi) {
    if(gi->gearUuid) {
      free(gi->gearUuid);
      gi->gearUuid = NULL;
    }

    if(gi->metadata) {
      hashtable_destroy(gi->metadata, 1);
      gi->metadata = NULL;
    }

    gi->prev->next = gi->next;
    gi->next->prev = gi->prev;

    free(gi);
  }
}
Esempio n. 16
0
static rsRetVal  /* assumes exclusive access to bucket */
dynstats_rebuildSurvivorTable(dynstats_bucket_t *b) {
	htable *survivor_table = NULL;
	htable *new_table = NULL;
	size_t htab_sz;
	DEFiRet;
	
	htab_sz = (size_t) (DYNSTATS_HASHTABLE_SIZE_OVERPROVISIONING * b->maxCardinality + 1);
	if (b->table == NULL) {
		CHKmalloc(survivor_table = create_hashtable(htab_sz, hash_from_string, key_equals_string,
			no_op_free));
	}
	CHKmalloc(new_table = create_hashtable(htab_sz, hash_from_string, key_equals_string, no_op_free));
	statsobj.UnlinkAllCounters(b->stats);
	if (b->survivor_table != NULL) {
		dynstats_destroyCountersIn(b, b->survivor_table, b->survivor_ctrs);
	}
	b->survivor_table = (b->table == NULL) ? survivor_table : b->table;
	b->survivor_ctrs = b->ctrs;
	b->table = new_table;
	b->ctrs = NULL;
finalize_it:
	if (iRet != RS_RET_OK) {
		LogError(errno, RS_RET_INTERNAL_ERROR, "error trying to evict "
			"TTL-expired metrics of dyn-stats bucket named: %s", b->name);
		if (new_table == NULL) {
			LogError(errno, RS_RET_INTERNAL_ERROR, "error trying to "
				"initialize hash-table for dyn-stats bucket named: %s", b->name);
		} else {
			assert(0); /* "can" not happen -- triggers Coverity CID 184307:
			hashtable_destroy(new_table, 0);
			We keep this as guard should code above change in the future */
		}
		if (b->table == NULL) {
			if (survivor_table == NULL) {
				LogError(errno, RS_RET_INTERNAL_ERROR, "error trying to initialize "
				"ttl-survivor hash-table for dyn-stats bucket named: %s", b->name);
			} else {
				hashtable_destroy(survivor_table, 0);
			}
		}
	}
	RETiRet;
}
Esempio n. 17
0
int main(int argc, char **argv)
{
    hash_t = hashtable_create();

    array_a = arraylist_create();
    hashtable_set(hash_t, "application name", "Test Application");

    arraylist_add(array_a, "abcd");
    LOG.debug = 1;
    //LOG.error_log_path = "error.log";
    log_init();
    log_debug("Starting server now...\n");
    config_init();
    parse_conf();
    read_logfile("./test.log");
    hashtable_destroy(hash_t);
    arraylist_destroy(array_a);
    return 0;
}
Esempio n. 18
0
static void
destroyStaticBondTable(void)
{
  hashtable_destroy(periodicHashtable, destroyElement);
  periodicHashtable = NULL;
  hashtable_destroy(bondStretchHashtable, destroyBondStretch);
  bondStretchHashtable = NULL;
  hashtable_destroy(bendDataHashtable, destroyBendData);
  bendDataHashtable = NULL;
  hashtable_destroy(deHashtable, destroyDeEntry);
  deHashtable = NULL;
  hashtable_destroy(vanDerWaalsHashtable, destroyVanDerWaals);
  vanDerWaalsHashtable = NULL;
  hashtable_destroy(electrostaticHashtable, destroyElectrostatic);
  electrostaticHashtable = NULL;
  hashtable_destroy(patternParameterHashtable, free);
  patternParameterHashtable = NULL;
}
Esempio n. 19
0
cinv_status_t cinv_structure_delete(CInvContext *context,
	CInvStructure *structure) {

	if (hashtable_count(structure->members) > 0) {
		struct hashtable_itr it;
		hashtable_iterator(structure->members, &it);

		do {
			free(hashtable_iterator_key(&it));
			free(hashtable_iterator_value(&it));
		} while (hashtable_iterator_remove(&it));
	}

	hashtable_destroy(structure->members, 0);

	free(structure);

	context_clear_error(context);
	return CINV_SUCCESS;
}
Esempio n. 20
0
void init_shp_hash(int clobber) {
    //fprintf(stderr," Initializing shape hash \n");
    // make sure we don't leak
    if (shp_hash) {
        if (clobber) {
            hashtable_destroy(shp_hash, 1);
            shp_hash=create_hashtable(SHP_HASH_SIZE,
                                      shape_hash_from_key,
                                      shape_keys_equal);
        }
    } else {
        shp_hash=create_hashtable(SHP_HASH_SIZE,
                                  shape_hash_from_key,
                                  shape_keys_equal);
    }

    // Now set the static timer value to the next time we need to run the purge
    // routine
    purge_time = sec_now() + PURGE_PERIOD;
}
Esempio n. 21
0
/** Release the memory behind the PCSCHEMA struct */
void 
pc_schema_free(PCSCHEMA *pcs)
{
	int i;

	for ( i = 0; i < pcs->ndims; i++ )
	{
		if ( pcs->dims[i] )
		{
			pc_dimension_free(pcs->dims[i]);
			pcs->dims[i] = 0;
		}
	}
	pcfree(pcs->dims);

    if ( pcs->namehash )
        hashtable_destroy(pcs->namehash, 0);
	
	pcfree(pcs);
}
Esempio n. 22
0
/*
* IndexLoadWords - load hashtable values into string buffer. Each word
* is loaded followed by (1) number indicating how many documents the word is in;
* (2) (a,b) pairs where the document a has b occurences of the word
* @ht: Hashtable to load from
* @buf: pointer to C-style string to loads values
*
*/
void IndexLoadWords(HashTable* ht, char** buf) 
{ 
  WordNode* wNode;
  for (int i = 0; i < MAX_HASH_SLOT; i++) { // Go through each hashtable bucket
    HashTableNode* node = ht->table[i];
    while (node) {  // Go through each word node
      if (node == NULL) {
        fprintf(stderr, "ERROR - IndexLoadWords");
        hashtable_destroy(ht);
        free(buf);
        exit(1);
      }
      wNode = node->data;
      wNode_concat(wNode, buf);

      node = node->next;
      
    }
  }
}
Esempio n. 23
0
/**
 * Free a value_t pointer, as well as any data stored within it. Container types
 * will be recursively freed.
 * @param value	value_t pointer to free
 */
void free_value(value_t *value) {
	list_t *listval, *cur, *temp;
	hashtable_t *hashval;
	hashtable_itr_t *itr;
	value_t *tempv;

	switch(value->type) {
	case INTTYPE:
	case BOOLTYPE:
	case LONGTYPE:
	case DOUBLETYPE:
		break;
	case STRINGTYPE:
	case REFTYPE:
		free(value->value.s);
		break;
	case INVOTYPE:
		free(value->value.v->name);
		tempv = encap_hash(value->value.v->params);
		free_value(tempv);
		break;
	case LISTTYPE:
		listval = value->value.l;
		list_for_each_safe(cur, temp, listval) {
			free_value((value_t*)cur->item);
			free(cur);
		}
		free(listval);
		break;
	case DICTTYPE:
		hashval = value->value.h;
		if (hashtable_count(hashval) > 0) {
			itr = hashtable_iterator(hashval);
			do {
				free_value((value_t*)hashtable_iterator_value(itr));
			} while (hashtable_iterator_advance(itr));
			free(itr);
		}
		hashtable_destroy(hashval, 0);
		break;
	}
Esempio n. 24
0
void
cache_indexes_empty(void)
{
	size_t *cached;
	struct hashtable_itr *itr;

	cached = indexcachescached;
	itr = hashtable_iterator(indexcachehash);
	if (hashtable_count(indexcachehash) > 0) {
		do {
			indexcache_t *ic;

			ic = hashtable_iterator_value(itr);
			if (ic == NULL)
				continue;
			munmap(ic->ptr, ic->size);
		} while (hashtable_iterator_advance(itr));
	}

	hashtable_destroy(indexcachehash, 1);
}
Esempio n. 25
0
int main(){
  struct hashtable ht;

  hashtable_init(&ht,1024,sizeof(int),sizeof(int));

  for(int i = 0; i < 20;i++){
    int value = i * 2;
    hashtable_set(&ht,&i,&value);
  }

  /* test remove */
  {
    int key = 5;
    hashtable_remove(&ht,&key);
  }

  /* test value retrieval */
  for(int i = 0; i < 20; i++){
    int value = 0;
    if(hashtable_get(&ht,&i,&value) == HT_KEY_NOT_FOUND){
      printf("Key not found\n");
    }else{
      printf("%d -> %d\n",i,value);
    }
  }

  /* test overwriting */
  {
    int key = 3;
    int value = 20;
    int ret = 0;
    hashtable_set(&ht,&key,&value);
    hashtable_get(&ht,&key,&ret);
    printf("%d -> %d\n",key,ret);
  }

  hashtable_destroy(&ht);

  return 0;
}
Esempio n. 26
0
File: cursor.c Progetto: Airr/Claro
int main(int argc, char *argv[])
{
	claro_base_init();
	claro_graphics_init();

    types = hashtable_str_create(4, FALSE, NULL);
    	
	log_fd_set_level(CL_DEBUG, stderr);
	
	clog(CL_INFO, "%s running using Claro!", __FILE__);
	
	w = window_widget_create(0, new_bounds(100, 100, 230, 80), 0);
	object_addhandler(w, "destroy", window_closed);
	window_set_title(w, "Cursor Types");
	
	c = combo_widget_create(w, new_bounds(10, 10, 210, -1), 0);
	object_addhandler(c, "selected", combo_selected);
	
    list_item_t * item = COMBO_APPEND(c, types, cCursorNormal);
    combo_select_item(c, item);
    COMBO_APPEND(c, types, cCursorTextEdit);
    COMBO_APPEND(c, types, cCursorWait);
    COMBO_APPEND(c, types, cCursorPoint);
    
    
	window_show(w);
	window_focus(w);
	
	block_heap_loginfo();
	
	claro_loop();
    
    hashtable_destroy(types);    
	
	return 0;
}
Esempio n. 27
0
void *
cache_free(cache_t *c)
{

    	cache_value_t *v;

    struct hashtable_itr *itr;
    if (hashtable_count(c->c_data) > 0)
    {
        itr = hashtable_iterator(c->c_data);
        do {
            v = hashtable_iterator_value(itr);

	    c->c_freevalue(v->p);
	    free(v);
        } while (hashtable_iterator_advance(itr));

     	free(itr);

    }

    hashtable_destroy(c->c_data,0); /* second arg indicates "free(value)" */

}
//-----------------------------------------------------------------------------
void
sgw_lite_cm_free_s_plus_p_gw_eps_bearer_context_information (
  s_plus_p_gw_eps_bearer_context_information_t * contextP)
//-----------------------------------------------------------------------------
{
  if (contextP == NULL) {
    return;
  }

  /*
   * if (contextP->sgw_eps_bearer_context_information.pdn_connections != NULL) {
   * obj_hashtable_destroy(contextP->sgw_eps_bearer_context_information.pdn_connections);
   * }
   */
  if (contextP->sgw_eps_bearer_context_information.pdn_connection.sgw_eps_bearers != NULL) {
    hashtable_destroy (contextP->sgw_eps_bearer_context_information.pdn_connection.sgw_eps_bearers);
  }

  if (contextP->pgw_eps_bearer_context_information.apns != NULL) {
    obj_hashtable_destroy (contextP->pgw_eps_bearer_context_information.apns);
  }

  free (contextP);
}
Esempio n. 29
0
double vector_entropy(unsigned long *vector, int nItems)
{
	int i;
	struct Item *aSingleItem;
	struct Single *aSingle;
	struct Hashtable singleTable;
	char key[128];
	double pi, rst = 0;

	hashtable_init(&singleTable, 100, (unsigned long(*)(void*))sdbm, (int(*)(void*, void*))single_has_name);
	for(i=0;i<nItems;i++) {
	      sprintf(key, "%ld", vector[i]);
	      aSingleItem = hashtable_find(&singleTable, key);
	      if(aSingleItem == NULL) {
		      aSingle = (struct Single*)malloc(sizeof(struct Single));
		      aSingle->t1 = vector[i];
		      aSingle->count = 1;
		      hashtable_add(&singleTable, key, aSingle);
	      } else {
		      aSingle = (struct Single*)aSingleItem->datap;
		      aSingle->count ++;
	      }
        }
	for (i=0;i<singleTable.size;i++) {
	      aSingleItem = singleTable.head[i];
	      while (aSingleItem != NULL) {
			aSingle = (struct Single*)aSingleItem->datap;
			pi = aSingle->count*1.0/nItems;
			rst -= pi*log(pi)/log(2);	
			aSingleItem = aSingleItem->next;
	      }
	}
	hashtable_destroy(&singleTable, free);
	return rst;

}
Esempio n. 30
0
void
print_distinct(int cutoff)
{
	struct hashtable *hash;
	DBC *dbcp;
	DBT key, data;
	int ret;

	//create_hashtable(1, hashfromkey_url, equalkeys_url);


	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

	/* Acquire a cursor for the database. */
	if ((ret = maindb->cursor(maindb, NULL, &dbcp, 0)) != 0) {
		maindb->err(maindb, ret, "DB->cursor");
		exit(1);
	}

	/* Walk through the database and print out the key/data pairs. */
	while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) {
		struct in_addr in;
		struct dbkey dbkey;
		struct dbkey dbkey2;
		struct dbkey dbkey3;
		unsigned int num;
		unsigned int i;
		char *url;
		DBT key2, data2;
		DBT key3, data3;
		char url2[10240];

		num = *(unsigned int *)data.data;
		memcpy(&dbkey, key.data, key.size);

		if (dbkey.num != 0)
			continue;
		in.s_addr = dbkey.addr;

		if (num < cutoff)
			continue;
		printf("Got %d record for %s\n", num, inet_ntoa(in));
#if 0
		hash = create_hashtable(10, hashfromkey_url, equalkeys_url);
		for (i = 1; i <= num; i++) {
			char *hashkey;
			dbkey2.addr = in.s_addr;
			if (num > 1)
				dbkey2.num = 2;
			else
				dbkey2.num = i;

			memset(&key2, 0, sizeof(key2));
			key2.data = &dbkey2;
			key2.size = sizeof(dbkey2);
			memset(&data2, 0, sizeof(data2));
			//data2.data = url2;
			//data2.size = sizeof(url2);

			if ((ret = maindb->get(maindb, NULL, &key2, &data2, 0) != 0)) {
				maindb->err(maindb, ret, "DBcursor->get");
				exit(1);
			}

			strncpy(url2, data2.data, data2.size);
			url2[data2.size] = '\0';
			//printf("\tFound: %d\n", data2.size);
			//printf("\tFound: %s\n", url2);

			hashkey = strdup(url2);
			if (hashkey == NULL)
				err(1, "Oops, hashkey is null");
			if (!hashtable_search(hash, url2)) {
				hashkey = strdup(url2);
				if (hashkey == NULL)
					err(1, "Oops, hashkey is null");

				hashtable_insert(hash, hashkey, &fakeval);
			}

		}
		if (num != hashtable_count(hash) && hashtable_count(hash) != 1) {
			printf("%d is really %d\n", num, hashtable_count(hash));
		}
		hashtable_destroy(hash, 0);
#endif
	}
	if (ret != DB_NOTFOUND) {
		maindb->err(maindb, ret, "DBcursor->c_get");
		exit(1);
	}

	if ((ret = dbcp->c_close(dbcp)) != 0)
		maindb->err(maindb, ret, "DBcursor->close");

}