Esempio n. 1
0
/*
 * Driver code
 */
int main()
{
    hash_table_t *table = NULL;

    table = hash_table_init(INITIAL_SIZE, 1);
    hash_table_insert(table, "hardik");
    hash_table_insert(table, "goel");
    hash_table_insert(table, "goel");
    hash_table_insert(table, "goel");
    hash_table_insert(table, "koel");
    hash_table_insert(table, "loge");
    hash_table_insert(table, "goel");
    hash_table_insert(table, "hardik");
    hash_table_insert(table, "aljkjkafd");
    hash_table_insert(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_insert(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_insert(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_insert(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_insert(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_print(table);
    hash_table_delete(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_delete(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_print(table);
    hash_table_insert(table, "asldfjasldkjsflasjdfashdfajkdhfkajjdsklfajslkdfjalsdkjfalkj");
    hash_table_print(table);
    hash_table_cleanup(table);

    return 0;
}
Esempio n. 2
0
File: main.c Progetto: ox/hash_table
int main(int argc, char ** argv) {
	int i;
  struct hash_table * table = hash_table_new(1);

  struct client * cli = malloc(sizeof(struct client));
  cli->name = "foo bar"; cli->credit = 5;
  hash_table_store(table, cli->name, cli);

  cli = malloc(sizeof(struct client));
  cli->name = "far bar"; cli->credit = 6;
  hash_table_store(table, cli->name, cli);

  cli = hash_table_delete(table, "foo bar"); /* returns the deleted value */
  printf("deleting: %i, should be 1\n", cli != NULL);
  cli = hash_table_delete(table, "doesn't exist"); /* returns NULL */
  printf("deleting: %i, should be 1\n", cli == NULL);

  struct client * cl2 = hash_table_get(table, "far bar");
  printf("%s has %i money\n", cl2->name, cl2->credit);

	/* get all of the keys and list them */
	char ** keys = hash_table_get_all_keys(table);
	for (i = 0; i < table->population; i++) {
		printf("key: %s\n", keys[i]);
	}

	free(keys);
	free(cli);
	free(cl2);

  hash_table_destroy(table, free_fn);
  return 0;
}
Esempio n. 3
0
void obj_free(obj_t * c)
{
	if( !c )
		return;	
	hash_table_delete( c->data );
	free(c);
}
Esempio n. 4
0
void deltadb_delete( struct deltadb *db )
{
  // should delete all nvpairs in the table here
	if(db->table) hash_table_delete(db->table);
	//if(db->logfile) fclose(db->logfile);
	free(db);
}
Esempio n. 5
0
int main(int argc, char* argv[])
{
	int i = 0;
	int n = 10000;
	int ret_data = 0;
	HashTable* hash_table = hash_table_create(NULL, NULL, hash_int, 31);

	for(i = 0; i < n; i++)
	{
		assert(hash_table_length(hash_table) == i);
		assert(hash_table_insert(hash_table, (void*)i) == RET_OK);
		assert(hash_table_length(hash_table) == (i + 1));
		assert(hash_table_find(hash_table, cmp_int, (void*)i, (void**)&ret_data) == RET_OK);
		assert(ret_data == i);
	}

	for(i = 0; i < n; i++)
	{
		assert(hash_table_delete(hash_table, cmp_int, (void*)i) == RET_OK);
		assert(hash_table_length(hash_table) == (n - i -1));
		assert(hash_table_find(hash_table, cmp_int, (void*)i, (void**)&ret_data) != RET_OK);
	}
	
	hash_table_destroy(hash_table);

	return 0;
}
Esempio n. 6
0
void makeflow_wrapper_delete(struct makeflow_wrapper *w)
{
	if(w->command)
		free(w->command);

	list_free(w->input_files);
	list_delete(w->input_files);

	list_free(w->output_files);
	list_delete(w->output_files);

	if(w->uses_remote_rename){
		uint64_t f;
		char *remote;
		itable_firstkey(w->remote_names);
		while(itable_nextkey(w->remote_names, &f, (void **) &remote)){
			free(remote);
		}
	}
	itable_delete(w->remote_names);

	hash_table_delete(w->remote_names_inv);

	free(w);
}
Esempio n. 7
0
/* new a HashTable instance */
HashTable* hash_table_new()
{
	HashTable* ht = malloc(sizeof(HashTable));
	if (NULL == ht) {
		hash_table_delete(ht);
		return NULL;
	}
	ht->table = malloc(sizeof(struct kv*) * TABLE_SIZE);
	if (NULL == ht->table) {
		hash_table_delete(ht);
		return NULL;
	}
	memset(ht->table, 0, sizeof(struct kv*) * TABLE_SIZE);

	return ht;
}
Esempio n. 8
0
// Delete an object from the cache, if it's still there
void cache_delete(cache_t cache, key_type key){
        item_t item_ptr = hash_table_find_item(cache->hash_table, key);
        if (item_ptr!=NULL){
            linked_list_delete(cache->linked_list, item_ptr->node_ptr);
            hash_table_delete(cache->hash_table, item_ptr);
        }
}
Esempio n. 9
0
void num_space_collapser_delete (num_space_collapser_t *nsc)
{
    hash_table_delete(nsc->hash_table);
    pthread_mutex_destroy(&nsc->mutex);

    free(nsc);
}
Esempio n. 10
0
/* Terminate timer sub-sytem */
static void timer_terminate(void)
{
   timer_flush_queues();

   assert(timer_id_hash);
   hash_table_delete(timer_id_hash);
   timer_id_hash = NULL;
}
Esempio n. 11
0
void pop_front() {
	if(head) {
		struct node *old_head = head;
		head = head->next;
		hash_table_delete(old_head->hash_table);
		free(old_head);
	}
}
Esempio n. 12
0
void hash_cache_delete(struct hash_cache *cache)
{
	if(cache) {
		if(cache->table)
			hash_table_delete(cache->table);
		free(cache);
	}
}
Esempio n. 13
0
// when we see }, go back one hash table and delete
void scope_leave(){
	// include check for null?
	// h = hash_table_lookup(h, "0prev");  // move h back
	h = h->prev;  // move h back
	hash_table_clear(h->next);
	hash_table_delete(h->next);
	h->next = NULL;
	// hash_table_clear(hash_table_lookup(h,"0next"));  // clear
	// hash_table_delete(hash_table_lookup(h,"0next"));  // delete table
} 
Esempio n. 14
0
int 
ps_unset_search(ps_decoder_t *ps, const char *name)
{
    ps_search_t *search = hash_table_delete(ps->searches, name);
    if (!search)
        return -1;
    if (ps->search == search)
        ps->search = NULL;
    ps_search_free(search);
    return 0;
}
Esempio n. 15
0
void batch_queue_delete(struct batch_queue *q)
{
    if(q) {
        char *key;
        char *value;

        debug(D_BATCH, "deleting queue %p", q);

        q->module->free(q);

        for (hash_table_firstkey(q->options); hash_table_nextkey(q->options, &key, (void **) &value); free(value))
            ;
        hash_table_delete(q->options);
        for (hash_table_firstkey(q->features); hash_table_nextkey(q->features, &key, (void **) &value); free(value))
            ;
        hash_table_delete(q->features);
        itable_delete(q->job_table);
        itable_delete(q->output_table);
        free(q);
    }
}
Esempio n. 16
0
File: ast.c Progetto: sdevlin/blang
void prog_free(struct prog **pp)
{
	if (!pp || !(*pp)) {
		return;
	}
	struct prog *p = *pp;
	decl_free(&p->ast);
	hash_table_delete(p->strings);
	symbol_free(&p->symbols);
	free(p);
	*pp = 0;
}
Esempio n. 17
0
void chirp_audit_delete(struct hash_table *table)
{
	char *key;
	struct chirp_audit *entry;

	hash_table_firstkey(table);
	while(hash_table_nextkey(table, &key, (void *) &entry)) {
		free(hash_table_remove(table, key));
	}

	hash_table_delete(table);
}
Esempio n. 18
0
void nvpair_delete(struct nvpair *n)
{
	char *key;
	void *value;

	if(!n) return;

	hash_table_firstkey(n->table);
	while(hash_table_nextkey(n->table, &key, &value)) {
		hash_table_remove(n->table, key);
		free(value);
	}
	hash_table_delete(n->table);
	free(n);
}
Esempio n. 19
0
int main() {
    hash_table* h = hash_table_new();
    hash_table_register_print(h, int_print);
    hash_table_register_copy(h, int_copy);
    hash_table_register_delete(h, int_delete);
    hash_table_print(h);
    char buff[3];
    int ints[20];
    for(int i=0; i < 20; i++) {
        ints[i] = i;
        sprintf(buff, "%i", i);
        hash_table_add(h, buff, &(ints[i]));
    }
    hash_table_print(h);
    hash_table_get(h, "1");
    hash_table_remove(h, "1");
    hash_table_print(h);
    hash_table_delete(h);
    return 0;
}
Esempio n. 20
0
int partychan_shutdown(void)
{
	partychan_t *chan, *next;
	partymember_common_t *common, *next_common;

	if (partychan_head != NULL) {
		for (chan = partychan_head; chan; ) {
			next = chan->next;
			partychan_delete(chan);
			chan = next;
		}
		partychan_head = NULL;
	}

	if (common_list_head) {
		for (common = common_list_head; common; ) {
			next_common = common->next;

			free(common->members);
			free(common);

			common = next_common;
		} 
		common_list_head = NULL;
	}

	bind_table_del(BT_partypub);
	bind_table_del(BT_partypart);
	bind_table_del(BT_partyjoin);
	
	/* flush any pending partychan deletes */
	garbage_run();

	hash_table_delete(cid_ht);

	return (0);
}
Esempio n. 21
0
void deltadb_delete( struct deltadb *db )
{
	if(db->table) hash_table_delete(db->table);
	free(db);
}
Esempio n. 22
0
void uhost_cache_destroy()
{
	hash_table_walk(uhost_cache_ht, uhost_cache_delete, NULL);
	hash_table_delete(uhost_cache_ht);
}
Esempio n. 23
0
static inline void remove_non_intersect_nodes(hkey_t node, Covg *covgs,
                                              Covg num, HashTable *ht)
{
  if(covgs[node] != num)
    hash_table_delete(ht, node);
}
Esempio n. 24
0
// Pseduo Unit Tests
int main(){
	hash_table * t = hash_table_new();

	// Does the hash function work correctly?
	printf("Testing Hash Function:\n");
	printf("----------------------\n");
	char test [5]	= {1,2,3,4,'\0'}; // these two keys collide with the default constants 
	char test2 [5]	= {4,8,5,4,'\0'}; // we will use this property later
	printf("hash: %d\n",hash(t,test));
	printf("hash: %d\n",hash(t,test2));
	printf("%s\n\n",(hash(t,test) == (((1 + 2 + 3 + 4) * MULTIPLY_PRIME ) % 11 )) ? "passed" : "failed");

	// Does the set function set and the get function get when there are no collisions?
	printf("Testing Set/Get Functions(no collision):\n");
	printf("----------------------------------------\n");
	int item = 12358;
	hash_table_set(t,test,&item);	
	printf("item = %d\n",(*(int *)hash_table_get(t,test)));
	printf("%s\n\n",(hash_table_get(t,test) == &item) ? "passed" : "failed");
	
	// Does the set function set and the get function get when there is a collision?
	printf("Testing Set/Get Functions(with collision):\n");
	printf("------------------------------------------\n");
	int item2 = 55555;
	hash_table_set(t,test2,&item2);	
	printf("%d\n",(*(int *)hash_table_get(t,test))); // get the original item, which will be down the chain
	printf("%d\n",(*(int *)hash_table_get(t,test2))); // get the second item, which will be on top
	printf("%s\n\n",(hash_table_get(t,test2) == &item2) ? "passed" : "failed");

	// Has the hash table been resized?
	printf("Testing whether the hash table has been resized:\n");
	printf("------------------------------------------\n");
	printf("hash: %d\n",hash(t,test));
	printf("hash: %d\n",hash(t,test2));
	printf("If so, these values should not be equal to the earlier hash values\n");
	printf("As a bonus, they will no longer collide, which is why the expansion was necessary in the first place\n\n");

	// Does get return NULL if nothing set?
	printf("Testing Get Failure:\n");
	printf("--------------------\n");
	printf("%x\n",hash_table_get(t,"abcdefgh"));
	printf("%s\n\n",(hash_table_get(t,"abcdefgh") == NULL) ? "passed" : "failed");



	// Some fun stuff
	hash_table * h = hash_table_new();

	char name[] = "Fake";
	hash_table_set(h,"first_name",&name);
	char last[] = "Person";
	hash_table_set(h,"last_name",&last);
	int age = 100;
	hash_table_set(h,"age",&age);

	printf("My full name is %s %s. I am %d years old\n",(char *)hash_table_get(h,"first_name"), (char *)hash_table_get(h,"last_name"),*((int*)hash_table_get(h,"age")));

	hash_table_delete(t);
	hash_table_delete(h);

}