boob map finished
This commit is contained in:
parent
83bbfe3386
commit
7fccb45259
2 changed files with 32 additions and 5 deletions
|
@ -19,6 +19,7 @@ glv_map_t* glv_map_create() {
|
|||
glv_map_t* glv_map_create_ex(int initial_size) {
|
||||
glv_map_t* map = malloc(sizeof(glv_map_t));
|
||||
map->buckets = NULL;
|
||||
map->bucket_lengths = NULL;
|
||||
map->pair_count = 0;
|
||||
|
||||
glv_map_resize(map, initial_size);
|
||||
|
@ -137,9 +138,37 @@ void glv_map_resize(glv_map_t* map, int size) {
|
|||
}
|
||||
|
||||
free(map->buckets);
|
||||
free(map->bucket_lengths);
|
||||
|
||||
map->buckets = new_buckets;
|
||||
map->bucket_lengths = new_lengths;
|
||||
map->bucket_count = size;
|
||||
}
|
||||
|
||||
void glv_map_destroy(glv_map_t* map) {
|
||||
glv_map_destroy_dealloc_func(map, NULL);
|
||||
}
|
||||
|
||||
void glv_map_destroy_dealloc(glv_map_t* map) {
|
||||
glv_map_destroy_dealloc_func(map, free);
|
||||
}
|
||||
|
||||
void glv_map_destroy_dealloc_func(glv_map_t* map, glv_map_dealloc_func func) {
|
||||
int i, j;
|
||||
|
||||
for(i = 0; i < map->bucket_count; ++i) {
|
||||
for(j = 0; j < map->bucket_lengths[i]; ++j) {
|
||||
free(map->buckets[i][j].key);
|
||||
if(func != NULL)
|
||||
func(map);
|
||||
}
|
||||
|
||||
free(map->buckets[i]);
|
||||
}
|
||||
|
||||
free(map->buckets);
|
||||
free(map->bucket_lengths);
|
||||
free(map);
|
||||
}
|
||||
|
||||
/** STRING HASHMAP END **/
|
|
@ -18,6 +18,8 @@ typedef struct {
|
|||
int pair_count;
|
||||
} glv_map_t;
|
||||
|
||||
typedef void (*glv_map_dealloc_func)(void*);
|
||||
|
||||
glv_map_t* glv_map_create();
|
||||
glv_map_t* glv_map_create_ex(int initial_size);
|
||||
|
||||
|
@ -29,17 +31,13 @@ void* glv_map_set_copy
|
|||
|
||||
void* glv_map_remove(glv_map_t* map, const char* key);
|
||||
void glv_map_remove_dealloc(glv_map_t* map, const char* key);
|
||||
void glv_map_remove_dealloc_func(glv_map_t* map, const char* key,);
|
||||
|
||||
void glv_map_clear(glv_map_t* map);
|
||||
void glv_map_clear_dealloc(glv_map_t* map);
|
||||
|
||||
int glv_map_has_key(glv_map_t* map, const char* key);
|
||||
void glv_map_resize(glv_map_t* map, int size);
|
||||
|
||||
void glv_map_destroy(glv_map_t* map);
|
||||
void glv_map_destroy_dealloc(glv_map_t* map);
|
||||
void glv_map_destroy_dealloc_func(glv_map_t* map, );
|
||||
void glv_map_destroy_dealloc_func(glv_map_t* map, glv_map_dealloc_func func);
|
||||
|
||||
/** STRING HASHMAP END **/
|
||||
|
||||
|
|
Reference in a new issue