summaryrefslogtreecommitdiff
path: root/src/shared/hashmap.h
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-09-15 16:43:59 -0400
committerAnthony G. Basile <blueness@gentoo.org>2014-09-15 16:43:59 -0400
commit7398282096ba4a74b11c18082cab7db32c2b0da1 (patch)
tree77eaf24ef7c223963ab4d498d5f350932b17ff6c /src/shared/hashmap.h
parent35257b404e1b449bcfbcbbf7dd4a713927bec8ed (diff)
hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in struct Hashmap separately. The functions always comprise a pair. Store a single pointer to struct hash_ops instead. systemd keeps hundreds of hashmaps, so this saves a little bit of memory. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/hashmap.h')
-rw-r--r--src/shared/hashmap.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
index b739262ab3..53b04eb033 100644
--- a/src/shared/hashmap.h
+++ b/src/shared/hashmap.h
@@ -41,27 +41,34 @@ typedef _IteratorStruct* Iterator;
typedef unsigned long (*hash_func_t)(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
typedef int (*compare_func_t)(const void *a, const void *b);
+struct hash_ops {
+ hash_func_t hash;
+ compare_func_t compare;
+};
+
unsigned long string_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
int string_compare_func(const void *a, const void *b) _pure_;
+extern const struct hash_ops string_hash_ops;
/* This will compare the passed pointers directly, and will not
* dereference them. This is hence not useful for strings or
* suchlike. */
unsigned long trivial_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
int trivial_compare_func(const void *a, const void *b) _const_;
+extern const struct hash_ops trivial_hash_ops;
-Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func);
+Hashmap *hashmap_new(const struct hash_ops *hash_ops);
void hashmap_free(Hashmap *h);
void hashmap_free_free(Hashmap *h);
int hashmap_put(Hashmap *h, const void *key, void *value);
void *hashmap_get(Hashmap *h, const void *key);
+void *hashmap_get2(Hashmap *h, const void *key, void **rkey);
bool hashmap_contains(Hashmap *h, const void *key);
unsigned hashmap_size(Hashmap *h) _pure_;
void *hashmap_iterate(Hashmap *h, Iterator *i, const void **key);
-void *hashmap_iterate_backwards(Hashmap *h, Iterator *i, const void **key);
void hashmap_clear(Hashmap *h);
void hashmap_clear_free(Hashmap *h);