Example #1
0
void tcache_clear() {
    iterator it;
    hashmap_iter_begin(&cache->entries, &it);
    hashmap_pair *pair;
    while((pair = iter_next(&it)) != NULL) {
        tcache_entry_value *entry = pair->val;
        SDL_DestroyTexture(entry->tex);
    }
    hashmap_clear(&cache->entries);
}
Example #2
0
void bk_free(bk *b) {
    surface_free(&b->background);
    vector_free(&b->palettes);

    // Free info structs
    iterator it;
    hashmap_iter_begin(&b->infos, &it);
    hashmap_pair *pair = NULL;
    while((pair = iter_next(&it)) != NULL) {
        bk_info_free((bk_info*)pair->val);
    }
    hashmap_free(&b->infos);
}
Example #3
0
void tcache_tick() {
    iterator it;
    hashmap_iter_begin(&cache->entries, &it);
    hashmap_pair *pair;
    while((pair = iter_next(&it)) != NULL) {
        tcache_entry_value *entry = pair->val;
        entry->age++;
        if(entry->age > CACHE_LIFETIME) {
            SDL_DestroyTexture(entry->tex);
            hashmap_delete(&cache->entries, &it);
            cache->old_frees++;
        }
    }
}
Example #4
0
int console_cmd_help(game_state *gs, int argc, char **argv) {
    // print list of commands
    vector sorted;
    iterator it;
    hashmap_pair *pair, **ppair;

    vector_create(&sorted, sizeof(hashmap_pair*));
    hashmap_iter_begin(&con->cmds, &it);
    while((pair = iter_next(&it)) != NULL) {
        vector_append(&sorted, &pair);
    }
    vector_sort(&sorted, &sort_command_by_name);
    vector_iter_begin(&sorted, &it);
    while((ppair = iter_next(&it)) != NULL) {
        char *name = (*ppair)->key;
        command *cmd = (*ppair)->val;
        console_output_add(name);
        console_output_add(" - ");
        console_output_addline(cmd->doc);
    }
    vector_free(&sorted);
    return 0;
}
Example #5
0
static void iter_test( void )
{
	int res;
	hashmap_t *hashmap;
	hashmap_iter_t iter;
	unsigned int count = 0;

	hashmap = hashmap_create();
	assert( hashmap );

	for( hashmap_iter_begin( hashmap, &iter );
	     !hashmap_iter_end( hashmap, &iter );
	     hashmap_iter_next( hashmap, &iter ) )
	{
		assert( 0 );
	}
	assert( 0 == count );

	res = hashmap_insert( hashmap, "test", 100 );
	assert( 0 == res );

	count = 0;
	for( hashmap_iter_begin( hashmap, &iter );
	     !hashmap_iter_end( hashmap, &iter );
	     hashmap_iter_next( hashmap, &iter ) )
	{
		hashmap_key_t key = hashmap_iter_key( &iter );
		hashmap_value_t value = hashmap_iter_value( &iter );

		assert( 0 == strcmp( key, "test" ) );
		assert( value == 100 );
		++count;
	}

	assert( 1 == count );

	res = hashmap_insert( hashmap, "next", 2 );
	assert( 0 == res );
	res = hashmap_insert( hashmap, "another", 3 );
	assert( 0 == res );
	res = hashmap_insert( hashmap, "yet another", 4 );
	assert( 0 == res );
	res = hashmap_insert( hashmap, "penultimate", 5 );
	assert( 0 == res );
	res = hashmap_insert( hashmap, "final", 5 );
	assert( 0 == res );

	count = 0;
	for( hashmap_iter_begin( hashmap, &iter );
	     !hashmap_iter_end( hashmap, &iter );
	     hashmap_iter_next( hashmap, &iter ) )
	{
		++count;
	}

	assert( 6 == count );


	hashmap_erase( hashmap, "penultimate" );
	count = 0;
	for( hashmap_iter_begin( hashmap, &iter );
	     !hashmap_iter_end( hashmap, &iter );
	     hashmap_iter_next( hashmap, &iter ) )
	{
		++count;
	}

	assert( 5 == count );

	hashmap_destroy( hashmap );
}