コード例 #1
0
ファイル: symtab.c プロジェクト: samjeba/cstuff
static void
expandtable(Symtab *table){
	Node **oldbuckets = table->buckets;
	const unsigned int oldsize = table->size;

	table->size *= RESIZE_FACTOR;
	table->buckets = xcalloc(table->size, sizeof(*table->buckets));
	table->entries = 0L;

	for(unsigned int i = 0; i < oldsize; i++){
		Node *np = oldbuckets[i];
		while(np){
			lookup(table, 1, np->key, np->value);
			np = np->next;
		}
	}
	freebuckets(oldbuckets, oldsize);
}
コード例 #2
0
ファイル: hashmap.c プロジェクト: nni013/http-inf2301
static void growmap(map_t *map)
{
    int b;
    int oldnumbuckets = map->numbuckets;
    mapentry_t **oldbuckets = map->buckets;

    map->size = 0;
    map->numbuckets = oldnumbuckets * 2;
    map->buckets = calloc(map->numbuckets, sizeof(mapentry_t *));
    if (map->buckets == NULL)
        fatal_error("out of memory");

    for (b = 0; b < oldnumbuckets; b++)
    {
        mapentry_t *e = oldbuckets[b];
        while (e != NULL)
        {
            map_put(map, e->key, e->value);
            e = e->next;
        }
    }
    freebuckets(oldnumbuckets, oldbuckets, NULL, NULL);
}   
コード例 #3
0
ファイル: hashmap.c プロジェクト: nni013/http-inf2301
void map_destroy(map_t *map, void (*destroy_key)(void *), void (*destroy_val)(void *))
{
    freebuckets(map->numbuckets, map->buckets, destroy_key, destroy_val);    
    free(map);
}
コード例 #4
0
ファイル: symtab.c プロジェクト: samjeba/cstuff
void
freesymboltable(Symtab *table){
	freebuckets(table->buckets, table->size);
	free(table);
}