#ifndef UTILS_STRINGMAP_H #define UTILS_STRINGMAP_H #include #include // https://stackoverflow.com/questions/7666509/hash-function-for-string // http://www.cse.yorku.ca/~oz/hash.html static inline size_t utils_string_hash_djb2(const unsigned char* value, size_t length) { size_t hash = 5381; for (size_t i = 0; i < length && value[i] != '\0'; ++i) hash = ((hash << 5) + hash) + value[i]; return hash; } typedef struct StringMap StringMap; StringMap* stringmap_new(void); void stringmap_delete(StringMap* map); size_t* stringmap_get(const StringMap* map, const char* key, size_t key_length); bool stringmap_has(const StringMap* map, const char* key, size_t key_length); void stringmap_set( StringMap* map, const char* key, size_t key_length, size_t value ); void stringmap_reserve(StringMap* map, size_t minimum_size); void stringmap_remove(StringMap* map, const char* key, size_t key_length); void stringmap_clean(StringMap* map); void stringmap_shrink(StringMap* map); void stringmap_clean_and_shrink(StringMap* map); size_t stringmap_length(StringMap* map); #endif