just squiddin
This commit is contained in:
parent
21806fce3a
commit
83bbfe3386
2 changed files with 19 additions and 6 deletions
|
@ -41,7 +41,7 @@ void* glv_map_set(glv_map_t* map, const char* key, void* value) {
|
|||
return NULL;
|
||||
|
||||
int hash = glv_map_hash_func(key), i;
|
||||
glv_pair_t* pair;
|
||||
glv_pair_t* pair = NULL;
|
||||
char* copy;
|
||||
void* tmp;
|
||||
|
||||
|
@ -62,16 +62,23 @@ void* glv_map_set(glv_map_t* map, const char* key, void* value) {
|
|||
|
||||
hash = hash % map->bucket_count;
|
||||
for(i = 0; i < map->bucket_lengths[hash]; ++i) {
|
||||
|
||||
if(map->buckets[hash][i].key == NULL) {
|
||||
pair = &(map->buckets[hash][i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(pair == NULL) {
|
||||
map->buckets[hash] =
|
||||
realloc(map->buckets[hash], ++(map->bucket_lengths[hash]));
|
||||
pair = &(map->buckets[hash][map->bucket_lengths[hash] - 1]);
|
||||
}
|
||||
|
||||
copy = malloc((strlen(key) + 1) * sizeof(char));
|
||||
strcpy(copy, key);
|
||||
|
||||
map->buckets[hash][map->bucket_lengths[hash] - 1].key = copy;
|
||||
map->buckets[hash][map->bucket_lengths[hash] - 1].value = value;
|
||||
pair->key = copy;
|
||||
pair->value = value;
|
||||
++(map->pair_count);
|
||||
}
|
||||
|
||||
|
@ -102,6 +109,10 @@ void* glv_map_remove(glv_map_t* map, const char* key) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void glv_map_remove_dealloc(glv_map_t* map, const char* key) {
|
||||
free(glv_map_remove(map, key));
|
||||
}
|
||||
|
||||
int glv_map_has_key(glv_map_t* map, const char* key) {
|
||||
return glv_map_get(map, key) == NULL;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ 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);
|
||||
|
@ -38,6 +39,7 @@ 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, );
|
||||
|
||||
/** STRING HASHMAP END **/
|
||||
|
||||
|
|
Reference in a new issue