do nont look

This commit is contained in:
malloc 2019-02-19 15:56:52 -06:00
parent ab49422e16
commit 712ac920c4
2 changed files with 37 additions and 2 deletions

View file

@ -40,6 +40,7 @@ void* glv_map_set(glv_map_t* map, const char* key, void* value) {
return NULL; return NULL;
int hash = glv_map_hash_func(key), i; int hash = glv_map_hash_func(key), i;
char* copy;
void* tmp; void* tmp;
if(glv_map_has_key(map, key)) { if(glv_map_has_key(map, key)) {
@ -52,7 +53,40 @@ void* glv_map_set(glv_map_t* map, const char* key, void* value) {
} }
} }
} else { } else {
if(map->pair_count + 1 > map->bucket_count * 2)
glv_map_resize(map, map->bucket_count * 2);
hash = hash % map->bucket_count;
map->buckets[hash] =
realloc(map->buckets[hash], ++(map->bucket_lengths[hash]));
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;
++(map->pair_count);
}
return NULL;
}
void* glv_map_set_copy
(glv_map_t* map, const char* key, void* value, size_t length)
{
void* copy = malloc(length);
memcpy(copy, value, length);
return glv_map_set(map, key, copy);
}
void* glv_map_remove(glv_map_t* map, const char* key) {
int hash = glv_map_hash_func(key) % map->bucket_count, i;
for(i = 0; i < map->bucket_lengths[hash]; ++i) {
if(strcmp(map->buckets[hash][i].key, key) == 0) {
}
} }
return NULL; return NULL;

View file

@ -24,7 +24,8 @@ glv_map_t* glv_map_create_ex(int initial_size);
void* glv_map_get(glv_map_t* map, const char* key); void* glv_map_get(glv_map_t* map, const char* key);
void* glv_map_set(glv_map_t* map, const char* key, void* value); void* glv_map_set(glv_map_t* map, const char* key, void* value);
void* glv_map_set_copy(glv_map_t* map, const char* key, void* value); void* glv_map_set_copy
(glv_map_t* map, const char* key, void* value, size_t length);
void* glv_map_remove(glv_map_t* map, const char* key); 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(glv_map_t* map, const char* key);