From e90f906024ef3dc002be3b13797cf871ebf35dc2 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Wed, 12 Feb 2020 10:45:35 +0200 Subject: [PATCH] lib: hash2 - Add string key helpers --- src/lib/hash2.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib/hash2.h b/src/lib/hash2.h index bdd1b53d80..d7febe612f 100644 --- a/src/lib/hash2.h +++ b/src/lib/hash2.h @@ -1,6 +1,8 @@ #ifndef HASH2_H #define HASH2_H +#include "hash.h" + struct hash2_iter { struct hash2_value *value, *next_value; unsigned int key_hash; @@ -40,4 +42,15 @@ void hash2_remove_iter(struct hash2_table *hash, struct hash2_iter *iter); /* Return the number of nodes in hash table. */ unsigned int hash2_count(const struct hash2_table *hash) ATTR_PURE; +/* can be used with string keys */ +static inline bool hash2_strcmp(const void *a, const void *b, void *ctx ATTR_UNUSED) +{ + return strcmp(a, b) == 0; +} + +static inline unsigned int hash2_str_hash(const void *key) +{ + return str_hash(key); +} + #endif -- 2.47.3