[systemd-commits] 5 commits - configure.ac Makefile.am src/analyze src/bus-proxyd src/cgtop src/core src/delta src/journal src/journal-remote src/libsystemd src/libsystemd-network src/locale src/login src/machine src/network src/readahead src/remount-fs src/resolve src/shared src/socket-proxy src/sysctl src/systemctl src/sysusers src/sysv-generator src/test src/tmpfiles

Michal Schmidt michich at kemper.freedesktop.org
Mon Sep 15 07:30:26 PDT 2014


 Makefile.am                             |    3 
 configure.ac                            |    1 
 src/analyze/analyze.c                   |    2 
 src/bus-proxyd/bus-policy.c             |    4 
 src/cgtop/cgtop.c                       |    4 
 src/core/automount.c                    |    4 
 src/core/bus-endpoint.c                 |    2 
 src/core/dbus-manager.c                 |    2 
 src/core/dbus.c                         |    2 
 src/core/device.c                       |    4 
 src/core/killall.c                      |    2 
 src/core/load-fragment.c                |   10 +-
 src/core/manager.c                      |   14 +--
 src/core/mount-setup.c                  |    2 
 src/core/swap.c                         |    4 
 src/core/transaction.c                  |    2 
 src/core/unit.c                         |   22 ++---
 src/delta/delta.c                       |    8 -
 src/journal-remote/journal-remote.c     |   18 +---
 src/journal/catalog.c                   |   11 +-
 src/journal/catalog.h                   |    3 
 src/journal/coredump-vacuum.c           |    2 
 src/journal/coredumpctl.c               |    2 
 src/journal/journal-file.c              |    2 
 src/journal/journalctl.c                |    2 
 src/journal/journald-server.c           |    2 
 src/journal/mmap-cache.c                |    4 
 src/journal/sd-journal.c                |    8 -
 src/journal/test-catalog.c              |    2 
 src/libsystemd-network/sd-dhcp-server.c |    8 +
 src/libsystemd/sd-bus/bus-match.c       |    4 
 src/libsystemd/sd-bus/bus-objects.c     |   13 ++
 src/libsystemd/sd-bus/bus-track.c       |    4 
 src/libsystemd/sd-bus/bus-util.c        |    2 
 src/libsystemd/sd-bus/busctl.c          |    2 
 src/libsystemd/sd-bus/sd-bus.c          |    2 
 src/libsystemd/sd-event/sd-event.c      |    4 
 src/libsystemd/sd-rtnl/sd-rtnl.c        |    2 
 src/locale/localectl.c                  |    2 
 src/login/logind-acl.c                  |    2 
 src/login/logind-session.c              |    2 
 src/login/logind.c                      |   18 ++--
 src/machine/machined.c                  |    6 -
 src/network/networkd-link.c             |    2 
 src/network/networkd-manager.c          |    8 -
 src/network/networkd-network.c          |    6 -
 src/network/networkd-wait-online-link.c |    5 -
 src/readahead/readahead-collect.c       |    2 
 src/remount-fs/remount-fs.c             |    2 
 src/resolve/resolved-dns-cache.c        |    2 
 src/resolve/resolved-dns-domain.c       |    5 +
 src/resolve/resolved-dns-domain.h       |    1 
 src/resolve/resolved-dns-packet.c       |    4 
 src/resolve/resolved-dns-query.c        |    4 
 src/resolve/resolved-dns-rr.c           |    9 +-
 src/resolve/resolved-dns-rr.h           |    4 
 src/resolve/resolved-dns-scope.c        |    2 
 src/resolve/resolved-dns-server.c       |    9 +-
 src/resolve/resolved-dns-server.h       |    3 
 src/resolve/resolved-dns-transaction.c  |    2 
 src/resolve/resolved-dns-zone.c         |    6 -
 src/resolve/resolved-link.c             |    2 
 src/resolve/resolved-manager.c          |    4 
 src/shared/cgroup-util.c                |    6 -
 src/shared/conf-files.c                 |    2 
 src/shared/fdset.c                      |    2 
 src/shared/hashmap.c                    |  140 +++++++++++---------------------
 src/shared/hashmap.h                    |   24 +++--
 src/shared/install.c                    |    8 -
 src/shared/locale-util.c                |    2 
 src/shared/logs-show.c                  |    2 
 src/shared/set.c                        |   20 ----
 src/shared/set.h                        |   10 --
 src/shared/util.c                       |    6 -
 src/socket-proxy/socket-proxyd.c        |    4 
 src/sysctl/sysctl.c                     |    2 
 src/systemctl/systemctl.c               |    6 -
 src/sysusers/sysusers.c                 |   22 ++---
 src/sysv-generator/sysv-generator.c     |    8 -
 src/test/test-hashmap.c                 |  101 +++++------------------
 src/test/test-install.c                 |    2 
 src/test/test-prioq.c                   |    7 +
 src/test/test-unit-file.c               |    2 
 src/tmpfiles/tmpfiles.c                 |    6 -
 84 files changed, 301 insertions(+), 382 deletions(-)

New commits:
commit 4dd6c5726d87a336888c0d871b9260c98f689016
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Mon Aug 4 22:54:10 2014 +0200

    sd-bus: use proper ITERATOR_FIRST abstraction
    
    Do not assume hashmap iterators are pointers.
    They may be structs in an alternative hashmap implementation.

diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index 0a3322a..4b6a8bf 100644
--- a/src/libsystemd/sd-bus/bus-track.c
+++ b/src/libsystemd/sd-bus/bus-track.c
@@ -245,7 +245,7 @@ _public_ const char* sd_bus_track_first(sd_bus_track *track) {
                 return NULL;
 
         track->modified = false;
-        track->iterator = NULL;
+        track->iterator = ITERATOR_FIRST;
 
         hashmap_iterate(track->names, &track->iterator, (const void**) &n);
         return n;

commit 923041cb0ab7c1795e74fa1ce4b38a6114727a3c
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Sun Aug 10 23:35:27 2014 +0200

    hashmap: minor hashmap_replace optimization
    
    When hashmap_replace detects no such key exists yet, it calls hashmap_put that
    performs the same check again. Avoid that by splitting the core of hashmap_put
    into a separate function.

diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
index 1eadece..4c51705 100644
--- a/src/shared/hashmap.c
+++ b/src/shared/hashmap.c
@@ -488,19 +488,10 @@ static bool resize_buckets(Hashmap *h) {
         return true;
 }
 
-int hashmap_put(Hashmap *h, const void *key, void *value) {
-        struct hashmap_entry *e;
-        unsigned hash;
-
-        assert(h);
+static int __hashmap_put(Hashmap *h, const void *key, void *value, unsigned hash) {
+        /* For when we know no such entry exists yet */
 
-        hash = bucket_hash(h, key);
-        e = hash_scan(h, hash, key);
-        if (e) {
-                if (e->value == value)
-                        return 0;
-                return -EEXIST;
-        }
+        struct hashmap_entry *e;
 
         if (resize_buckets(h))
                 hash = bucket_hash(h, key);
@@ -521,6 +512,23 @@ int hashmap_put(Hashmap *h, const void *key, void *value) {
         return 1;
 }
 
+int hashmap_put(Hashmap *h, const void *key, void *value) {
+        struct hashmap_entry *e;
+        unsigned hash;
+
+        assert(h);
+
+        hash = bucket_hash(h, key);
+        e = hash_scan(h, hash, key);
+        if (e) {
+                if (e->value == value)
+                        return 0;
+                return -EEXIST;
+        }
+
+        return __hashmap_put(h, key, value, hash);
+}
+
 int hashmap_replace(Hashmap *h, const void *key, void *value) {
         struct hashmap_entry *e;
         unsigned hash;
@@ -535,7 +543,7 @@ int hashmap_replace(Hashmap *h, const void *key, void *value) {
                 return 0;
         }
 
-        return hashmap_put(h, key, value);
+        return __hashmap_put(h, key, value, hash);
 }
 
 int hashmap_update(Hashmap *h, const void *key, void *value) {

commit 631b9deefbef76c5f69b165f33cb46690c938c95
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Thu Jul 31 18:04:20 2014 +0200

    hashmap, set: remove unused functions
    
    The following hashmap_* and set_* functions/macros have never had any
    users in systemd's history:
    
      *_iterate_backwards
      *_iterate_skip
      *_last
      *_FOREACH_BACKWARDS
    
    Remove this dead code.

diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
index 715484c..1eadece 100644
--- a/src/shared/hashmap.c
+++ b/src/shared/hashmap.c
@@ -753,59 +753,6 @@ at_end:
         return NULL;
 }
 
-void *hashmap_iterate_backwards(Hashmap *h, Iterator *i, const void **key) {
-        struct hashmap_entry *e;
-
-        assert(i);
-
-        if (!h)
-                goto at_beginning;
-
-        if (*i == ITERATOR_FIRST)
-                goto at_beginning;
-
-        if (*i == ITERATOR_LAST && !h->iterate_list_tail)
-                goto at_beginning;
-
-        e = *i == ITERATOR_LAST ? h->iterate_list_tail : (struct hashmap_entry*) *i;
-
-        if (e->iterate_previous)
-                *i = (Iterator) e->iterate_previous;
-        else
-                *i = ITERATOR_FIRST;
-
-        if (key)
-                *key = e->key;
-
-        return e->value;
-
-at_beginning:
-        *i = ITERATOR_FIRST;
-
-        if (key)
-                *key = NULL;
-
-        return NULL;
-}
-
-void *hashmap_iterate_skip(Hashmap *h, const void *key, Iterator *i) {
-        unsigned hash;
-        struct hashmap_entry *e;
-
-        if (!h)
-                return NULL;
-
-        hash = bucket_hash(h, key);
-
-        e = hash_scan(h, hash, key);
-        if (!e)
-                return NULL;
-
-        *i = (Iterator) e;
-
-        return e->value;
-}
-
 void* hashmap_first(Hashmap *h) {
 
         if (!h)
@@ -828,17 +775,6 @@ void* hashmap_first_key(Hashmap *h) {
         return (void*) h->iterate_list_head->key;
 }
 
-void* hashmap_last(Hashmap *h) {
-
-        if (!h)
-                return NULL;
-
-        if (!h->iterate_list_tail)
-                return NULL;
-
-        return h->iterate_list_tail->value;
-}
-
 void* hashmap_steal_first(Hashmap *h) {
         void *data;
 
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
index 7385ebc..e25840f 100644
--- a/src/shared/hashmap.h
+++ b/src/shared/hashmap.h
@@ -109,8 +109,6 @@ bool hashmap_isempty(Hashmap *h) _pure_;
 unsigned hashmap_buckets(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_iterate_skip(Hashmap *h, const void *key, Iterator *i);
 
 void hashmap_clear(Hashmap *h);
 void hashmap_clear_free(Hashmap *h);
@@ -120,7 +118,6 @@ void *hashmap_steal_first(Hashmap *h);
 void *hashmap_steal_first_key(Hashmap *h);
 void *hashmap_first(Hashmap *h) _pure_;
 void *hashmap_first_key(Hashmap *h) _pure_;
-void *hashmap_last(Hashmap *h) _pure_;
 
 void *hashmap_next(Hashmap *h, const void *key);
 
@@ -132,9 +129,6 @@ char **hashmap_get_strv(Hashmap *h);
 #define HASHMAP_FOREACH_KEY(e, k, h, i) \
         for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), (const void**) &(k)); (e); (e) = hashmap_iterate((h), &(i), (const void**) &(k)))
 
-#define HASHMAP_FOREACH_BACKWARDS(e, h, i) \
-        for ((i) = ITERATOR_LAST, (e) = hashmap_iterate_backwards((h), &(i), NULL); (e); (e) = hashmap_iterate_backwards((h), &(i), NULL))
-
 DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free);
 DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free);
 DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free_free);
diff --git a/src/shared/set.c b/src/shared/set.c
index d4ffe05..ed16067 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -125,14 +125,6 @@ void *set_iterate(Set *s, Iterator *i) {
         return hashmap_iterate(MAKE_HASHMAP(s), i, NULL);
 }
 
-void *set_iterate_backwards(Set *s, Iterator *i) {
-        return hashmap_iterate_backwards(MAKE_HASHMAP(s), i, NULL);
-}
-
-void *set_iterate_skip(Set *s, void *value, Iterator *i) {
-        return hashmap_iterate_skip(MAKE_HASHMAP(s), value, i);
-}
-
 void *set_steal_first(Set *s) {
         return hashmap_steal_first(MAKE_HASHMAP(s));
 }
@@ -141,10 +133,6 @@ void* set_first(Set *s) {
         return hashmap_first(MAKE_HASHMAP(s));
 }
 
-void* set_last(Set *s) {
-        return hashmap_last(MAKE_HASHMAP(s));
-}
-
 int set_merge(Set *s, Set *other) {
         return hashmap_merge(MAKE_HASHMAP(s), MAKE_HASHMAP(other));
 }
diff --git a/src/shared/set.h b/src/shared/set.h
index e650b7e..840ee0a 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -57,24 +57,18 @@ unsigned set_size(Set *s);
 bool set_isempty(Set *s);
 
 void *set_iterate(Set *s, Iterator *i);
-void *set_iterate_backwards(Set *s, Iterator *i);
-void *set_iterate_skip(Set *s, void *value, Iterator *i);
 
 void set_clear(Set *s);
 void set_clear_free(Set *s);
 
 void *set_steal_first(Set *s);
 void* set_first(Set *s);
-void* set_last(Set *s);
 
 char **set_get_strv(Set *s);
 
 #define SET_FOREACH(e, s, i) \
         for ((i) = ITERATOR_FIRST, (e) = set_iterate((s), &(i)); (e); (e) = set_iterate((s), &(i)))
 
-#define SET_FOREACH_BACKWARDS(e, s, i) \
-        for ((i) = ITERATOR_LAST, (e) = set_iterate_backwards((s), &(i)); (e); (e) = set_iterate_backwards((s), &(i)))
-
 DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free);
 DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free);
 #define _cleanup_set_free_ _cleanup_(set_freep)
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
index 95a7f83..d9863f8 100644
--- a/src/test/test-hashmap.c
+++ b/src/test/test-hashmap.c
@@ -343,44 +343,6 @@ static void test_hashmap_foreach(void) {
         hashmap_free_free(m);
 }
 
-static void test_hashmap_foreach_backwards(void) {
-        Hashmap *m;
-        Iterator i;
-        char *val1, *val2, *val3, *val4, *s;
-        bool value_found[] = { false, false, false, false };
-
-        val1 = strdup("my val1");
-        assert_se(val1);
-        val2 = strdup("my val2");
-        assert_se(val2);
-        val3 = strdup("my val3");
-        assert_se(val3);
-        val4 = strdup("my val4");
-        assert_se(val4);
-
-        m = hashmap_new(&string_hash_ops);
-        hashmap_put(m, "Key 1", val1);
-        hashmap_put(m, "Key 2", val2);
-        hashmap_put(m, "Key 3", val3);
-        hashmap_put(m, "Key 4", val4);
-
-        HASHMAP_FOREACH_BACKWARDS(s, m, i) {
-                if (!value_found[0] && streq(s, val1))
-                        value_found[0] = true;
-                else if (!value_found[1] && streq(s, val2))
-                        value_found[1] = true;
-                else if (!value_found[2] && streq(s, val3))
-                        value_found[2] = true;
-                else if (!value_found[3] && streq(s, val4))
-                        value_found[3] = true;
-        }
-
-        assert_se(m);
-        assert_se(value_found[0] && value_found[1] && value_found[2] && value_found[3]);
-
-        hashmap_free_free(m);
-}
-
 static void test_hashmap_merge(void) {
         Hashmap *m;
         Hashmap *n;
@@ -532,21 +494,6 @@ static void test_hashmap_first_key(void) {
         assert_se(streq(hashmap_first_key(m), "key 2"));
 }
 
-static void test_hashmap_last(void) {
-        _cleanup_hashmap_free_ Hashmap *m = NULL;
-
-        m = hashmap_new(&string_hash_ops);
-        assert_se(m);
-
-        assert_se(!hashmap_last(m));
-        assert_se(hashmap_put(m, "key 1", (void *) (const char *) "val 1") == 1);
-        assert_se(streq(hashmap_last(m), "val 1"));
-        assert_se(hashmap_put(m, "key 2", (void *) (const char *) "bar") == 1);
-        assert_se(streq(hashmap_last(m), "bar"));
-        assert_se(hashmap_remove(m, "key 2"));
-        assert_se(streq(hashmap_last(m), "val 1"));
-}
-
 static void test_hashmap_steal_first_key(void) {
         _cleanup_hashmap_free_ Hashmap *m = NULL;
 
@@ -604,7 +551,6 @@ int main(int argc, const char *argv[]) {
         test_hashmap_remove_and_put();
         test_hashmap_ensure_allocated();
         test_hashmap_foreach();
-        test_hashmap_foreach_backwards();
         test_hashmap_foreach_key();
         test_hashmap_contains();
         test_hashmap_merge();
@@ -613,7 +559,6 @@ int main(int argc, const char *argv[]) {
         test_hashmap_size();
         test_hashmap_many();
         test_hashmap_first_key();
-        test_hashmap_last();
         test_hashmap_steal_first_key();
         test_hashmap_clear_free_free();
         test_uint64_compare_func();

commit d5099efc47d4e6ac60816b5381a5f607ab03f06e
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Wed Aug 13 01:00:18 2014 +0200

    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.

diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 82f5cf3..5e55988 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -907,7 +907,7 @@ static int analyze_critical_chain(sd_bus *bus, char *names[]) {
         if (n <= 0)
                 return n;
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         if (!h)
                 return -ENOMEM;
 
diff --git a/src/bus-proxyd/bus-policy.c b/src/bus-proxyd/bus-policy.c
index 06c16a7..d2eace9 100644
--- a/src/bus-proxyd/bus-policy.c
+++ b/src/bus-proxyd/bus-policy.c
@@ -338,7 +338,7 @@ static int file_load(Policy *p, const char *path) {
 
                                         assert_cc(sizeof(uid_t) == sizeof(uint32_t));
 
-                                        r = hashmap_ensure_allocated(&p->user_items, trivial_hash_func, trivial_compare_func);
+                                        r = hashmap_ensure_allocated(&p->user_items, NULL);
                                         if (r < 0)
                                                 return log_oom();
 
@@ -369,7 +369,7 @@ static int file_load(Policy *p, const char *path) {
 
                                         assert_cc(sizeof(gid_t) == sizeof(uint32_t));
 
-                                        r = hashmap_ensure_allocated(&p->group_items, trivial_hash_func, trivial_compare_func);
+                                        r = hashmap_ensure_allocated(&p->group_items, NULL);
                                         if (r < 0)
                                                 return log_oom();
 
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 509fe4c..ab8c4cf 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -695,8 +695,8 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 goto finish;
 
-        a = hashmap_new(string_hash_func, string_compare_func);
-        b = hashmap_new(string_hash_func, string_compare_func);
+        a = hashmap_new(&string_hash_ops);
+        b = hashmap_new(&string_hash_ops);
         if (!a || !b) {
                 r = log_oom();
                 goto finish;
diff --git a/src/core/automount.c b/src/core/automount.c
index 73a8ce1..f72aca2 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -685,7 +685,7 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
                         log_debug_unit(u->id, "Failed to parse token value %s", value);
                 else {
                         if (!a->tokens)
-                                if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func)))
+                                if (!(a->tokens = set_new(NULL)))
                                         return -ENOMEM;
 
                         r = set_put(a->tokens, UINT_TO_PTR(token));
@@ -762,7 +762,7 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo
                 } else
                         log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
 
-                r = set_ensure_allocated(&a->tokens, trivial_hash_func, trivial_compare_func);
+                r = set_ensure_allocated(&a->tokens, NULL);
                 if (r < 0) {
                         log_error_unit(UNIT(a)->id, "Failed to allocate token set.");
                         goto fail;
diff --git a/src/core/bus-endpoint.c b/src/core/bus-endpoint.c
index 8d11974..1e8f07e 100644
--- a/src/core/bus-endpoint.c
+++ b/src/core/bus-endpoint.c
@@ -55,7 +55,7 @@ int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess a
                         return 0;
                 }
         } else {
-                ep->policy_hash = hashmap_new(string_hash_func, string_compare_func);
+                ep->policy_hash = hashmap_new(&string_hash_ops);
                 if (!ep->policy_hash)
                         return -ENOMEM;
         }
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 2fe9d19..533ce43 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1399,7 +1399,7 @@ static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *us
         if (r < 0)
                 return r;
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         if (!h)
                 return -ENOMEM;
 
diff --git a/src/core/dbus.c b/src/core/dbus.c
index e7eee3c..09b4a4a 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -659,7 +659,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
                 return 0;
         }
 
-        r = set_ensure_allocated(&m->private_buses, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&m->private_buses, NULL);
         if (r < 0) {
                 log_oom();
                 return 0;
diff --git a/src/core/device.c b/src/core/device.c
index 0f28a16..11c4261 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -304,7 +304,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
                         goto fail;
                 }
 
-                r = hashmap_ensure_allocated(&m->devices_by_sysfs, string_hash_func, string_compare_func);
+                r = hashmap_ensure_allocated(&m->devices_by_sysfs, &string_hash_ops);
                 if (r < 0)
                         goto fail;
 
@@ -517,7 +517,7 @@ static int device_following_set(Unit *u, Set **_set) {
                 return 0;
         }
 
-        set = set_new(NULL, NULL);
+        set = set_new(NULL);
         if (!set)
                 return -ENOMEM;
 
diff --git a/src/core/killall.c b/src/core/killall.c
index 291e1f9..a6ff50a 100644
--- a/src/core/killall.c
+++ b/src/core/killall.c
@@ -205,7 +205,7 @@ void broadcast_signal(int sig, bool wait_for_exit, bool send_sighup) {
         _cleanup_set_free_ Set *pids = NULL;
 
         if (wait_for_exit)
-                pids = set_new(trivial_hash_func, trivial_compare_func);
+                pids = set_new(NULL);
 
         assert_se(sigemptyset(&mask) == 0);
         assert_se(sigaddset(&mask, SIGCHLD) == 0);
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 7cf19b9..0620882 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2276,7 +2276,7 @@ int config_parse_syscall_filter(
         }
 
         if (!c->syscall_filter) {
-                c->syscall_filter = set_new(trivial_hash_func, trivial_compare_func);
+                c->syscall_filter = set_new(NULL);
                 if (!c->syscall_filter)
                         return log_oom();
 
@@ -2368,7 +2368,7 @@ int config_parse_syscall_archs(
                 return 0;
         }
 
-        r = set_ensure_allocated(archs, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(archs, NULL);
         if (r < 0)
                 return log_oom();
 
@@ -2474,7 +2474,7 @@ int config_parse_address_families(
         }
 
         if (!c->address_families) {
-                c->address_families = set_new(trivial_hash_func, trivial_compare_func);
+                c->address_families = set_new(NULL);
                 if (!c->address_families)
                         return log_oom();
 
@@ -3092,7 +3092,7 @@ int config_parse_set_status(
                         }
                 }
 
-                r = set_ensure_allocated(&status_set->status, NULL, NULL);
+                r = set_ensure_allocated(&status_set->status, NULL);
                 if (r < 0)
                         return log_oom();
 
@@ -3423,7 +3423,7 @@ static int load_from_path(Unit *u, const char *path) {
         assert(u);
         assert(path);
 
-        symlink_names = set_new(string_hash_func, string_compare_func);
+        symlink_names = set_new(&string_hash_ops);
         if (!symlink_names)
                 return -ENOMEM;
 
diff --git a/src/core/manager.c b/src/core/manager.c
index 095111e..0770727 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -449,27 +449,27 @@ int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) {
         if (r < 0)
                 goto fail;
 
-        r = hashmap_ensure_allocated(&m->units, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&m->units, &string_hash_ops);
         if (r < 0)
                 goto fail;
 
-        r = hashmap_ensure_allocated(&m->jobs, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&m->jobs, NULL);
         if (r < 0)
                 goto fail;
 
-        r = hashmap_ensure_allocated(&m->cgroup_unit, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&m->cgroup_unit, &string_hash_ops);
         if (r < 0)
                 goto fail;
 
-        r = hashmap_ensure_allocated(&m->watch_bus, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&m->watch_bus, &string_hash_ops);
         if (r < 0)
                 goto fail;
 
-        r = set_ensure_allocated(&m->startup_units, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&m->startup_units, NULL);
         if (r < 0)
                 goto fail;
 
-        r = set_ensure_allocated(&m->failed_units, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&m->failed_units, NULL);
         if (r < 0)
                 goto fail;
 
@@ -903,7 +903,7 @@ static void manager_build_unit_path_cache(Manager *m) {
 
         set_free_free(m->unit_path_cache);
 
-        m->unit_path_cache = set_new(string_hash_func, string_compare_func);
+        m->unit_path_cache = set_new(&string_hash_ops);
         if (!m->unit_path_cache) {
                 log_error("Failed to allocate unit path cache.");
                 return;
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index cc2633e..23a66d2 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -235,7 +235,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
                 return 0;
         }
 
-        controllers = set_new(string_hash_func, string_compare_func);
+        controllers = set_new(&string_hash_ops);
         if (!controllers)
                 return log_oom();
 
diff --git a/src/core/swap.c b/src/core/swap.c
index 019d32e..b88a914 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -77,7 +77,7 @@ static int swap_set_devnode(Swap *s, const char *devnode) {
 
         assert(s);
 
-        r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&UNIT(s)->manager->swaps_by_devnode, &string_hash_ops);
         if (r < 0)
                 return r;
 
@@ -1226,7 +1226,7 @@ static int swap_following_set(Unit *u, Set **_set) {
                 return 0;
         }
 
-        set = set_new(NULL, NULL);
+        set = set_new(NULL);
         if (!set)
                 return -ENOMEM;
 
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 1f4c9ce..dbb4133 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -1143,7 +1143,7 @@ Transaction *transaction_new(bool irreversible) {
         if (!tr)
                 return NULL;
 
-        tr->jobs = hashmap_new(trivial_hash_func, trivial_compare_func);
+        tr->jobs = hashmap_new(NULL);
         if (!tr->jobs) {
                 free(tr);
                 return NULL;
diff --git a/src/core/unit.c b/src/core/unit.c
index b5c3182..5978e21 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -81,7 +81,7 @@ Unit *unit_new(Manager *m, size_t size) {
         if (!u)
                 return NULL;
 
-        u->names = set_new(string_hash_func, string_compare_func);
+        u->names = set_new(&string_hash_ops);
         if (!u->names) {
                 free(u);
                 return NULL;
@@ -1843,17 +1843,17 @@ int unit_watch_pid(Unit *u, pid_t pid) {
         /* Watch a specific PID. We only support one or two units
          * watching each PID for now, not more. */
 
-        r = set_ensure_allocated(&u->pids, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&u->pids, NULL);
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&u->manager->watch_pids1, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&u->manager->watch_pids1, NULL);
         if (r < 0)
                 return r;
 
         r = hashmap_put(u->manager->watch_pids1, LONG_TO_PTR(pid), u);
         if (r == -EEXIST) {
-                r = hashmap_ensure_allocated(&u->manager->watch_pids2, trivial_hash_func, trivial_compare_func);
+                r = hashmap_ensure_allocated(&u->manager->watch_pids2, NULL);
                 if (r < 0)
                         return r;
 
@@ -2086,22 +2086,22 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
                 return 0;
         }
 
-        r = set_ensure_allocated(&u->dependencies[d], trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&u->dependencies[d], NULL);
         if (r < 0)
                 return r;
 
         if (inverse_table[d] != _UNIT_DEPENDENCY_INVALID) {
-                r = set_ensure_allocated(&other->dependencies[inverse_table[d]], trivial_hash_func, trivial_compare_func);
+                r = set_ensure_allocated(&other->dependencies[inverse_table[d]], NULL);
                 if (r < 0)
                         return r;
         }
 
         if (add_reference) {
-                r = set_ensure_allocated(&u->dependencies[UNIT_REFERENCES], trivial_hash_func, trivial_compare_func);
+                r = set_ensure_allocated(&u->dependencies[UNIT_REFERENCES], NULL);
                 if (r < 0)
                         return r;
 
-                r = set_ensure_allocated(&other->dependencies[UNIT_REFERENCED_BY], trivial_hash_func, trivial_compare_func);
+                r = set_ensure_allocated(&other->dependencies[UNIT_REFERENCED_BY], NULL);
                 if (r < 0)
                         return r;
         }
@@ -2847,7 +2847,7 @@ static Set *unit_pid_set(pid_t main_pid, pid_t control_pid) {
         Set *pid_set;
         int r;
 
-        pid_set = set_new(trivial_hash_func, trivial_compare_func);
+        pid_set = set_new(NULL);
         if (!pid_set)
                 return NULL;
 
@@ -3385,7 +3385,7 @@ int unit_require_mounts_for(Unit *u, const char *path) {
                         char *q;
 
                         if (!u->manager->units_requiring_mounts_for) {
-                                u->manager->units_requiring_mounts_for = hashmap_new(string_hash_func, string_compare_func);
+                                u->manager->units_requiring_mounts_for = hashmap_new(&string_hash_ops);
                                 if (!u->manager->units_requiring_mounts_for)
                                         return -ENOMEM;
                         }
@@ -3394,7 +3394,7 @@ int unit_require_mounts_for(Unit *u, const char *path) {
                         if (!q)
                                 return -ENOMEM;
 
-                        x = set_new(NULL, NULL);
+                        x = set_new(NULL);
                         if (!x) {
                                 free(q);
                                 return -ENOMEM;
diff --git a/src/delta/delta.c b/src/delta/delta.c
index cd8bd35..91f8592 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -268,7 +268,7 @@ static int enumerate_dir_d(Hashmap *top, Hashmap *bottom, Hashmap *drops, const
 
                 h = hashmap_get(drops, unit);
                 if (!h) {
-                        h = hashmap_new(string_hash_func, string_compare_func);
+                        h = hashmap_new(&string_hash_ops);
                         if (!h)
                                 return -ENOMEM;
                         hashmap_put(drops, unit, h);
@@ -372,9 +372,9 @@ static int process_suffix(const char *suffix, const char *onlyprefix) {
 
         dropins = nulstr_contains(have_dropins, suffix);
 
-        top = hashmap_new(string_hash_func, string_compare_func);
-        bottom = hashmap_new(string_hash_func, string_compare_func);
-        drops = hashmap_new(string_hash_func, string_compare_func);
+        top = hashmap_new(&string_hash_ops);
+        bottom = hashmap_new(&string_hash_ops);
+        drops = hashmap_new(&string_hash_ops);
         if (!top || !bottom || !drops) {
                 r = -ENOMEM;
                 goto finish;
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index 1cc86ae..12de820 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -222,20 +222,14 @@ static int open_output(Writer *w, const char* host) {
  **********************************************************************/
 
 static int init_writer_hashmap(RemoteServer *s) {
-        static const struct {
-                hash_func_t hash_func;
-                compare_func_t compare_func;
-        } functions[] = {
-                [JOURNAL_WRITE_SPLIT_NONE] = {trivial_hash_func,
-                                              trivial_compare_func},
-                [JOURNAL_WRITE_SPLIT_HOST] = {string_hash_func,
-                                              string_compare_func},
+        static const struct hash_ops *hash_ops[] = {
+                [JOURNAL_WRITE_SPLIT_NONE] = NULL,
+                [JOURNAL_WRITE_SPLIT_HOST] = &string_hash_ops,
         };
 
-        assert(arg_split_mode >= 0 && arg_split_mode < (int) ELEMENTSOF(functions));
+        assert(arg_split_mode >= 0 && arg_split_mode < (int) ELEMENTSOF(hash_ops));
 
-        s->writers = hashmap_new(functions[arg_split_mode].hash_func,
-                                 functions[arg_split_mode].compare_func);
+        s->writers = hashmap_new(hash_ops[arg_split_mode]);
         if (!s->writers)
                 return log_oom();
 
@@ -695,7 +689,7 @@ static int setup_microhttpd_server(RemoteServer *s,
                 goto error;
         }
 
-        r = hashmap_ensure_allocated(&s->daemons, uint64_hash_func, uint64_compare_func);
+        r = hashmap_ensure_allocated(&s->daemons, &uint64_hash_ops);
         if (r < 0) {
                 log_oom();
                 goto error;
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index f03357d..41d450b 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -64,7 +64,7 @@ typedef struct CatalogItem {
         le64_t offset;
 } CatalogItem;
 
-unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
+static unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
         const CatalogItem *i = p;
         uint64_t u;
         size_t l, sz;
@@ -81,7 +81,7 @@ unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_S
         return (unsigned long) u;
 }
 
-int catalog_compare_func(const void *a, const void *b) {
+static int catalog_compare_func(const void *a, const void *b) {
         const CatalogItem *i = a, *j = b;
         unsigned k;
 
@@ -95,6 +95,11 @@ int catalog_compare_func(const void *a, const void *b) {
         return strcmp(i->language, j->language);
 }
 
+const struct hash_ops catalog_hash_ops = {
+        .hash = catalog_hash_func,
+        .compare = catalog_compare_func
+};
+
 static int finish_item(
                 Hashmap *h,
                 struct strbuf *sb,
@@ -407,7 +412,7 @@ int catalog_update(const char* database, const char* root, const char* const* di
         unsigned n;
         long r;
 
-        h = hashmap_new(catalog_hash_func, catalog_compare_func);
+        h = hashmap_new(&catalog_hash_ops);
         sb = strbuf_new();
 
         if (!h || !sb) {
diff --git a/src/journal/catalog.h b/src/journal/catalog.h
index fdde67a..a72ecf6 100644
--- a/src/journal/catalog.h
+++ b/src/journal/catalog.h
@@ -28,11 +28,10 @@
 #include "strbuf.h"
 
 int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path);
-unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
-int catalog_compare_func(const void *a, const void *b) _pure_;
 int catalog_update(const char* database, const char* root, const char* const* dirs);
 int catalog_get(const char* database, sd_id128_t id, char **data);
 int catalog_list(FILE *f, const char* database, bool oneline);
 int catalog_list_items(FILE *f, const char* database, bool oneline, char **items);
 int catalog_file_lang(const char *filename, char **lang);
 extern const char * const catalog_file_dirs[];
+extern const struct hash_ops catalog_hash_ops;
diff --git a/src/journal/coredump-vacuum.c b/src/journal/coredump-vacuum.c
index 125bb3a..fec901e 100644
--- a/src/journal/coredump-vacuum.c
+++ b/src/journal/coredump-vacuum.c
@@ -194,7 +194,7 @@ int coredump_vacuum(int exclude_fd, off_t keep_free, off_t max_use) {
                             exclude_st.st_ino == st.st_ino)
                                 continue;
 
-                        r = hashmap_ensure_allocated(&h, NULL, NULL);
+                        r = hashmap_ensure_allocated(&h, NULL);
                         if (r < 0)
                                 return log_oom();
 
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 34dcae8..d4756fe 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -58,7 +58,7 @@ static Set *new_matches(void) {
         char *tmp;
         int r;
 
-        set = set_new(trivial_hash_func, trivial_compare_func);
+        set = set_new(NULL);
         if (!set) {
                 log_oom();
                 return NULL;
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 7286e14..f25cda6 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2498,7 +2498,7 @@ int journal_file_open(
                 goto fail;
         }
 
-        f->chain_cache = hashmap_new(uint64_hash_func, uint64_compare_func);
+        f->chain_cache = hashmap_new(&uint64_hash_ops);
         if (!f->chain_cache) {
                 r = -ENOMEM;
                 goto fail;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index d00a815..47206d3 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1029,7 +1029,7 @@ static int get_possible_units(sd_journal *j,
         const char *field;
         int r;
 
-        found = set_new(string_hash_func, string_compare_func);
+        found = set_new(&string_hash_ops);
         if (!found)
                 return log_oom();
 
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 01da38b..3df7416 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1483,7 +1483,7 @@ int server_init(Server *s) {
 
         mkdir_p("/run/systemd/journal", 0755);
 
-        s->user_journals = hashmap_new(trivial_hash_func, trivial_compare_func);
+        s->user_journals = hashmap_new(NULL);
         if (!s->user_journals)
                 return log_oom();
 
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 908562d..2d268fc 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -227,7 +227,7 @@ static Context *context_add(MMapCache *m, unsigned id) {
         if (c)
                 return c;
 
-        r = hashmap_ensure_allocated(&m->contexts, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&m->contexts, NULL);
         if (r < 0)
                 return NULL;
 
@@ -281,7 +281,7 @@ static FileDescriptor* fd_add(MMapCache *m, int fd) {
         if (f)
                 return f;
 
-        r = hashmap_ensure_allocated(&m->fds, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&m->fds, NULL);
         if (r < 0)
                 return NULL;
 
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 693707c..1fc9f01 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -70,7 +70,7 @@ static int set_put_error(sd_journal *j, int r) {
         if (r >= 0)
                 return r;
 
-        k = set_ensure_allocated(&j->errors, trivial_hash_func, trivial_compare_func);
+        k = set_ensure_allocated(&j->errors, NULL);
         if (k < 0)
                 return k;
 
@@ -1662,7 +1662,7 @@ static int allocate_inotify(sd_journal *j) {
         }
 
         if (!j->directories_by_wd) {
-                j->directories_by_wd = hashmap_new(trivial_hash_func, trivial_compare_func);
+                j->directories_by_wd = hashmap_new(NULL);
                 if (!j->directories_by_wd)
                         return -ENOMEM;
         }
@@ -1688,8 +1688,8 @@ static sd_journal *journal_new(int flags, const char *path) {
                         goto fail;
         }
 
-        j->files = hashmap_new(string_hash_func, string_compare_func);
-        j->directories_by_path = hashmap_new(string_hash_func, string_compare_func);
+        j->files = hashmap_new(&string_hash_ops);
+        j->directories_by_path = hashmap_new(&string_hash_ops);
         j->mmap = mmap_cache_new();
         if (!j->files || !j->directories_by_path || !j->mmap)
                 goto fail;
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 967ab67..5fe2f6a 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -62,7 +62,7 @@ static void test_catalog_importing(void) {
         Hashmap *h;
         struct strbuf *sb;
 
-        assert_se(h = hashmap_new(catalog_hash_func, catalog_compare_func));
+        assert_se(h = hashmap_new(&catalog_hash_ops));
         assert_se(sb = strbuf_new());
 
 #define BUF "xxx"
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index ab68322..a6d6178 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -109,6 +109,11 @@ int client_id_compare_func(const void *_a, const void *_b) {
         return memcmp(a->data, b->data, a->length);
 }
 
+static const struct hash_ops client_id_hash_ops = {
+        .hash = client_id_hash_func,
+        .compare = client_id_compare_func
+};
+
 static void dhcp_lease_free(DHCPLease *lease) {
         if (!lease)
                 return;
@@ -158,8 +163,7 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
         server->address = htobe32(INADDR_ANY);
         server->netmask = htobe32(INADDR_ANY);
         server->index = ifindex;
-        server->leases_by_client_id = hashmap_new(client_id_hash_func,
-                                                  client_id_compare_func);
+        server->leases_by_client_id = hashmap_new(&client_id_hash_ops);
 
         *ret = server;
         server = NULL;
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index 88b61a7..18afe0f 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -450,13 +450,13 @@ static int bus_match_add_compare_value(
                 where->child = c;
 
                 if (t == BUS_MATCH_MESSAGE_TYPE) {
-                        c->compare.children = hashmap_new(trivial_hash_func, trivial_compare_func);
+                        c->compare.children = hashmap_new(NULL);
                         if (!c->compare.children) {
                                 r = -ENOMEM;
                                 goto fail;
                         }
                 } else if (BUS_MATCH_CAN_HASH(t)) {
-                        c->compare.children = hashmap_new(string_hash_func, string_compare_func);
+                        c->compare.children = hashmap_new(&string_hash_ops);
                         if (!c->compare.children) {
                                 r = -ENOMEM;
                                 goto fail;
diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c
index 3a2de65..81c840f 100644
--- a/src/libsystemd/sd-bus/bus-objects.c
+++ b/src/libsystemd/sd-bus/bus-objects.c
@@ -225,7 +225,7 @@ static int get_child_nodes(
         assert(n);
         assert(_s);
 
-        s = set_new(string_hash_func, string_compare_func);
+        s = set_new(&string_hash_ops);
         if (!s)
                 return -ENOMEM;
 
@@ -1420,7 +1420,7 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) {
         if (n)
                 return n;
 
-        r = hashmap_ensure_allocated(&bus->nodes, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&bus->nodes, &string_hash_ops);
         if (r < 0)
                 return NULL;
 
@@ -1590,6 +1590,11 @@ static int vtable_member_compare_func(const void *a, const void *b) {
         return strcmp(x->member, y->member);
 }
 
+static const struct hash_ops vtable_member_hash_ops = {
+        .hash = vtable_member_hash_func,
+        .compare = vtable_member_compare_func
+};
+
 static int add_object_vtable_internal(
                 sd_bus *bus,
                 sd_bus_slot **slot,
@@ -1618,11 +1623,11 @@ static int add_object_vtable_internal(
                       !streq(interface, "org.freedesktop.DBus.Peer") &&
                       !streq(interface, "org.freedesktop.DBus.ObjectManager"), -EINVAL);
 
-        r = hashmap_ensure_allocated(&bus->vtable_methods, vtable_member_hash_func, vtable_member_compare_func);
+        r = hashmap_ensure_allocated(&bus->vtable_methods, &vtable_member_hash_ops);
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&bus->vtable_properties, vtable_member_hash_func, vtable_member_compare_func);
+        r = hashmap_ensure_allocated(&bus->vtable_properties, &vtable_member_hash_ops);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index ffa2cf3..0a3322a 100644
--- a/src/libsystemd/sd-bus/bus-track.c
+++ b/src/libsystemd/sd-bus/bus-track.c
@@ -166,7 +166,7 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
         assert_return(track, -EINVAL);
         assert_return(service_name_is_valid(name), -EINVAL);
 
-        r = hashmap_ensure_allocated(&track->names, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&track->names, &string_hash_ops);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index a85d361..7c6da60 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -399,7 +399,7 @@ int bus_verify_polkit_async(
         if (!sender)
                 return -EBADMSG;
 
-        r = hashmap_ensure_allocated(registry, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(registry, NULL);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c
index af71804..f06b745 100644
--- a/src/libsystemd/sd-bus/busctl.c
+++ b/src/libsystemd/sd-bus/busctl.c
@@ -76,7 +76,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
 
         pager_open_if_enabled();
 
-        names = hashmap_new(string_hash_func, string_compare_func);
+        names = hashmap_new(&string_hash_ops);
         if (!names)
                 return log_oom();
 
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 83b3aa1..33b65ab 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1756,7 +1756,7 @@ _public_ int sd_bus_call_async(
         if (!BUS_IS_OPEN(bus->state))
                 return -ENOTCONN;
 
-        r = hashmap_ensure_allocated(&bus->reply_callbacks, uint64_hash_func, uint64_compare_func);
+        r = hashmap_ensure_allocated(&bus->reply_callbacks, &uint64_hash_ops);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 985ff28..b56182d 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -1032,7 +1032,7 @@ _public_ int sd_event_add_child(
         assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
         assert_return(!event_pid_changed(e), -ECHILD);
 
-        r = hashmap_ensure_allocated(&e->child_sources, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&e->child_sources, NULL);
         if (r < 0)
                 return r;
 
@@ -1123,7 +1123,7 @@ _public_ int sd_event_add_post(
         assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
         assert_return(!event_pid_changed(e), -ECHILD);
 
-        r = set_ensure_allocated(&e->post_sources, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&e->post_sources, NULL);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
index a3f314b..b7f1afe 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
@@ -557,7 +557,7 @@ int sd_rtnl_call_async(sd_rtnl *nl,
         assert_return(callback, -EINVAL);
         assert_return(!rtnl_pid_changed(nl), -ECHILD);
 
-        r = hashmap_ensure_allocated(&nl->reply_callbacks, uint64_hash_func, uint64_compare_func);
+        r = hashmap_ensure_allocated(&nl->reply_callbacks, &uint64_hash_ops);
         if (r < 0)
                 return r;
 
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 2bb0d3b..bf8b7b2 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -272,7 +272,7 @@ static int list_vconsole_keymaps(sd_bus *bus, char **args, unsigned n) {
         _cleanup_strv_free_ char **l = NULL;
         const char *dir;
 
-        keymaps = set_new(string_hash_func, string_compare_func);
+        keymaps = set_new(&string_hash_ops);
         if (!keymaps)
                 return log_oom();
 
diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c
index b76e16d..f7c6f3a 100644
--- a/src/login/logind-acl.c
+++ b/src/login/logind-acl.c
@@ -190,7 +190,7 @@ int devnode_acl_all(struct udev *udev,
 
         assert(udev);
 
-        nodes = set_new(string_hash_func, string_compare_func);
+        nodes = set_new(&string_hash_ops);
         if (!nodes)
                 return -ENOMEM;
 
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 10a43a4..eeb58c9 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -61,7 +61,7 @@ Session* session_new(Manager *m, const char *id) {
                 return NULL;
         }
 
-        s->devices = hashmap_new(devt_hash_func, devt_compare_func);
+        s->devices = hashmap_new(&devt_hash_ops);
         if (!s->devices) {
                 free(s->state_file);
                 free(s);
diff --git a/src/login/logind.c b/src/login/logind.c
index 1f94a97..f1b6a86 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -64,17 +64,17 @@ Manager *manager_new(void) {
 
         m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */
 
-        m->devices = hashmap_new(string_hash_func, string_compare_func);
-        m->seats = hashmap_new(string_hash_func, string_compare_func);
-        m->sessions = hashmap_new(string_hash_func, string_compare_func);
-        m->users = hashmap_new(trivial_hash_func, trivial_compare_func);
-        m->inhibitors = hashmap_new(string_hash_func, string_compare_func);
-        m->buttons = hashmap_new(string_hash_func, string_compare_func);
+        m->devices = hashmap_new(&string_hash_ops);
+        m->seats = hashmap_new(&string_hash_ops);
+        m->sessions = hashmap_new(&string_hash_ops);
+        m->users = hashmap_new(NULL);
+        m->inhibitors = hashmap_new(&string_hash_ops);
+        m->buttons = hashmap_new(&string_hash_ops);
 
-        m->user_units = hashmap_new(string_hash_func, string_compare_func);
-        m->session_units = hashmap_new(string_hash_func, string_compare_func);
+        m->user_units = hashmap_new(&string_hash_ops);
+        m->session_units = hashmap_new(&string_hash_ops);
 
-        m->busnames = set_new(string_hash_func, string_compare_func);
+        m->busnames = set_new(&string_hash_ops);
 
         if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames ||
             !m->user_units || !m->session_units)
diff --git a/src/machine/machined.c b/src/machine/machined.c
index aac670b..71c8189 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -44,9 +44,9 @@ Manager *manager_new(void) {
         if (!m)
                 return NULL;
 
-        m->machines = hashmap_new(string_hash_func, string_compare_func);
-        m->machine_units = hashmap_new(string_hash_func, string_compare_func);
-        m->machine_leaders = hashmap_new(trivial_hash_func, trivial_compare_func);
+        m->machines = hashmap_new(&string_hash_ops);
+        m->machine_units = hashmap_new(&string_hash_ops);
+        m->machine_leaders = hashmap_new(NULL);
 
         if (!m->machines || !m->machine_units || !m->machine_leaders) {
                 manager_free(m);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 11ac130..9bf1a81 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -206,7 +206,7 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
         if (r < 0)
                 return -ENOMEM;
 
-        r = hashmap_ensure_allocated(&manager->links, NULL, NULL);
+        r = hashmap_ensure_allocated(&manager->links, NULL);
         if (r < 0)
                 return r;
 
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 1614bc0..2213ad7 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -115,7 +115,7 @@ int manager_new(Manager **ret) {
                         return -ENOMEM;
         }
 
-        m->netdevs = hashmap_new(string_hash_func, string_compare_func);
+        m->netdevs = hashmap_new(&string_hash_ops);
         if (!m->netdevs)
                 return -ENOMEM;
 
@@ -485,15 +485,15 @@ int manager_save(Manager *m) {
         assert(m->state_file);
 
         /* We add all NTP and DNS server to a set, to filter out duplicates */
-        dns = set_new(string_hash_func, string_compare_func);
+        dns = set_new(&string_hash_ops);
         if (!dns)
                 return -ENOMEM;
 
-        ntp = set_new(string_hash_func, string_compare_func);
+        ntp = set_new(&string_hash_ops);
         if (!ntp)
                 return -ENOMEM;
 
-        domains = set_new(string_hash_func, string_compare_func);
+        domains = set_new(&string_hash_ops);
         if (!domains)
                 return -ENOMEM;
 
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index a2e27e0..aad9923 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -63,15 +63,15 @@ static int network_load_one(Manager *manager, const char *filename) {
         LIST_HEAD_INIT(network->static_addresses);
         LIST_HEAD_INIT(network->static_routes);
 
-        network->stacked_netdevs = hashmap_new(string_hash_func, string_compare_func);
+        network->stacked_netdevs = hashmap_new(&string_hash_ops);
         if (!network->stacked_netdevs)
                 return log_oom();
 
-        network->addresses_by_section = hashmap_new(NULL, NULL);
+        network->addresses_by_section = hashmap_new(NULL);
         if (!network->addresses_by_section)
                 return log_oom();
 
-        network->routes_by_section = hashmap_new(NULL, NULL);
+        network->routes_by_section = hashmap_new(NULL);
         if (!network->routes_by_section)
                 return log_oom();
 
diff --git a/src/network/networkd-wait-online-link.c b/src/network/networkd-wait-online-link.c
index f23c7ce..268ab67 100644
--- a/src/network/networkd-wait-online-link.c
+++ b/src/network/networkd-wait-online-link.c
@@ -34,12 +34,11 @@ int link_new(Manager *m, Link **ret, int ifindex, const char *ifname) {
         assert(m);
         assert(ifindex > 0);
 
-        r = hashmap_ensure_allocated(&m->links, NULL, NULL);
+        r = hashmap_ensure_allocated(&m->links, NULL);
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&m->links_by_name,
-                                     string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&m->links_by_name, &string_hash_ops);
         if (r < 0)
                 return r;
 
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 1592cc8..822a803 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -282,7 +282,7 @@ static int collect(const char *root) {
                 goto finish;
         }
 
-        files = hashmap_new(string_hash_func, string_compare_func);
+        files = hashmap_new(&string_hash_ops);
         if (!files) {
                 log_error("Failed to allocate set.");
                 r = -ENOMEM;
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index 847637a..cd7cfe7 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        pids = hashmap_new(trivial_hash_func, trivial_compare_func);
+        pids = hashmap_new(NULL);
         if (!pids) {
                 log_error("Failed to allocate set");
                 goto finish;
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index 733ef63..33ca4d1 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -186,7 +186,7 @@ static int dns_cache_init(DnsCache *c) {
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&c->by_key, dns_resource_key_hash_func, dns_resource_key_compare_func);
+        r = hashmap_ensure_allocated(&c->by_key, &dns_resource_key_hash_ops);
         if (r < 0)
                 return r;
 
diff --git a/src/resolve/resolved-dns-domain.c b/src/resolve/resolved-dns-domain.c
index 8ed1ecf..e1eb3dd 100644
--- a/src/resolve/resolved-dns-domain.c
+++ b/src/resolve/resolved-dns-domain.c
@@ -371,6 +371,11 @@ int dns_name_compare_func(const void *a, const void *b) {
         }
 }
 
+const struct hash_ops dns_name_hash_ops = {
+        .hash = dns_name_hash_func,
+        .compare = dns_name_compare_func
+};
+
 int dns_name_equal(const char *x, const char *y) {
         int r, q, k, w;
 
diff --git a/src/resolve/resolved-dns-domain.h b/src/resolve/resolved-dns-domain.h
index e674c5d..0888a78 100644
--- a/src/resolve/resolved-dns-domain.h
+++ b/src/resolve/resolved-dns-domain.h
@@ -37,6 +37,7 @@ int dns_name_normalize(const char *s, char **_ret);
 
 unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_SIZE]);
 int dns_name_compare_func(const void *a, const void *b);
+extern const struct hash_ops dns_name_hash_ops;
 
 int dns_name_equal(const char *x, const char *y);
 int dns_name_endswith(const char *name, const char *suffix);
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index 0d276df..7375f77 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -433,9 +433,7 @@ int dns_packet_append_name(DnsPacket *p, const char *name,
                         goto fail;
 
                 if (allow_compression) {
-                        r = hashmap_ensure_allocated(&p->names,
-                                                     dns_name_hash_func,
-                                                     dns_name_compare_func);
+                        r = hashmap_ensure_allocated(&p->names, &dns_name_hash_ops);
                         if (r < 0)
                                 goto fail;
 
diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c
index 669595d..f0483c9 100644
--- a/src/resolve/resolved-dns-query.c
+++ b/src/resolve/resolved-dns-query.c
@@ -144,7 +144,7 @@ static int dns_query_add_transaction(DnsQuery *q, DnsScope *s, DnsResourceKey *k
         assert(q);
         assert(s);
 
-        r = set_ensure_allocated(&q->transactions, NULL, NULL);
+        r = set_ensure_allocated(&q->transactions, NULL);
         if (r < 0)
                 return r;
 
@@ -166,7 +166,7 @@ static int dns_query_add_transaction(DnsQuery *q, DnsScope *s, DnsResourceKey *k
                         return r;
         }
 
-        r = set_ensure_allocated(&t->queries, NULL, NULL);
+        r = set_ensure_allocated(&t->queries, NULL);
         if (r < 0)
                 goto gc;
 
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index c5f7cb9..fd5ecf4 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -133,7 +133,7 @@ int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRec
         return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
 }
 
-unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
+static unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
         const DnsResourceKey *k = i;
         unsigned long ul;
 
@@ -144,7 +144,7 @@ unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[H
         return ul;
 }
 
-int dns_resource_key_compare_func(const void *a, const void *b) {
+static int dns_resource_key_compare_func(const void *a, const void *b) {
         const DnsResourceKey *x = a, *y = b;
         int ret;
 
@@ -165,6 +165,11 @@ int dns_resource_key_compare_func(const void *a, const void *b) {
         return 0;
 }
 
+const struct hash_ops dns_resource_key_hash_ops = {
+        .hash = dns_resource_key_hash_func,
+        .compare = dns_resource_key_compare_func
+};
+
 int dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
         char cbuf[DECIMAL_STR_MAX(uint16_t)], tbuf[DECIMAL_STR_MAX(uint16_t)];
         const char *c, *t;
diff --git a/src/resolve/resolved-dns-rr.h b/src/resolve/resolved-dns-rr.h
index 3222f1f..9d9a89d 100644
--- a/src/resolve/resolved-dns-rr.h
+++ b/src/resolve/resolved-dns-rr.h
@@ -159,8 +159,6 @@ DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
 int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
 int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr);
 int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr);
-unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]);
-int dns_resource_key_compare_func(const void *a, const void *b);
 int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
 
@@ -175,3 +173,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
 
 const char *dns_class_to_string(uint16_t type);
 int dns_class_from_string(const char *name, uint16_t *class);
+
+extern const struct hash_ops dns_resource_key_hash_ops;
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 039a754..40d5992 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -709,7 +709,7 @@ int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr) {
 
         /* We don't send these queries immediately. Instead, we queue
          * them, and send them after some jitter delay. */
-        r = hashmap_ensure_allocated(&scope->conflict_queue, dns_resource_key_hash_func, dns_resource_key_compare_func);
+        r = hashmap_ensure_allocated(&scope->conflict_queue, &dns_resource_key_hash_ops);
         if (r < 0) {
                 log_oom();
                 return r;
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index c99768b..caf06fe 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -100,7 +100,7 @@ DnsServer* dns_server_free(DnsServer *s)  {
         return NULL;
 }
 
-unsigned long dns_server_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
+static unsigned long dns_server_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
         const DnsServer *s = p;
         uint64_t u;
 
@@ -110,7 +110,7 @@ unsigned long dns_server_hash_func(const void *p, const uint8_t hash_key[HASH_KE
         return u;
 }
 
-int dns_server_compare_func(const void *a, const void *b) {
+static int dns_server_compare_func(const void *a, const void *b) {
         const DnsServer *x = a, *y = b;
 
         if (x->family < y->family)
@@ -120,3 +120,8 @@ int dns_server_compare_func(const void *a, const void *b) {
 
         return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family));
 }
+
+const struct hash_ops dns_server_hash_ops = {
+        .hash = dns_server_hash_func,
+        .compare = dns_server_compare_func
+};
diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h
index f2361a8..a438a27 100644
--- a/src/resolve/resolved-dns-server.h
+++ b/src/resolve/resolved-dns-server.h
@@ -60,5 +60,4 @@ int dns_server_new(
 
 DnsServer* dns_server_free(DnsServer *s);
 
-unsigned long dns_server_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
-int dns_server_compare_func(const void *a, const void *b);
+extern const struct hash_ops dns_server_hash_ops;
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index 990b1f2..74b0634 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -78,7 +78,7 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsQuestion *q) {
         assert(s);
         assert(q);
 
-        r = hashmap_ensure_allocated(&s->manager->dns_transactions, NULL, NULL);
+        r = hashmap_ensure_allocated(&s->manager->dns_transactions, NULL);
         if (r < 0)
                 return r;
 
diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c
index b53e957..8098ff5 100644
--- a/src/resolve/resolved-dns-zone.c
+++ b/src/resolve/resolved-dns-zone.c
@@ -126,11 +126,11 @@ static int dns_zone_init(DnsZone *z) {
 
         assert(z);
 
-        r = hashmap_ensure_allocated(&z->by_key, dns_resource_key_hash_func, dns_resource_key_compare_func);
+        r = hashmap_ensure_allocated(&z->by_key, &dns_resource_key_hash_ops);
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&z->by_name, dns_name_hash_func, dns_name_compare_func);
+        r = hashmap_ensure_allocated(&z->by_name, &dns_name_hash_ops);
         if (r < 0)
                 return r;
 
@@ -194,7 +194,7 @@ static int dns_zone_item_probe_start(DnsZoneItem *i)  {
                         return r;
         }
 
-        r = set_ensure_allocated(&t->zone_items, NULL, NULL);
+        r = set_ensure_allocated(&t->zone_items, NULL);
         if (r < 0)
                 goto gc;
 
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index f47017c..4def672 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -33,7 +33,7 @@ int link_new(Manager *m, Link **ret, int ifindex) {
         assert(m);
         assert(ifindex > 0);
 
-        r = hashmap_ensure_allocated(&m->links, NULL, NULL);
+        r = hashmap_ensure_allocated(&m->links, NULL);
         if (r < 0)
                 return r;
 
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 00aaffe..63d7845 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -737,11 +737,11 @@ int manager_write_resolv_conf(Manager *m) {
         manager_read_resolv_conf(m);
 
         /* Add the full list to a set, to filter out duplicates */
-        dns = set_new(dns_server_hash_func, dns_server_compare_func);
+        dns = set_new(&dns_server_hash_ops);
         if (!dns)
                 return -ENOMEM;
 
-        domains = set_new(dns_name_hash_func, dns_name_compare_func);
+        domains = set_new(&dns_name_hash_ops);
         if (!domains)
                 return -ENOMEM;
 
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 00eac64..da8e885 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -161,7 +161,7 @@ int cg_kill(const char *controller, const char *path, int sig, bool sigcont, boo
          * tasks list, to properly handle forking processes */
 
         if (!s) {
-                s = allocated_set = set_new(trivial_hash_func, trivial_compare_func);
+                s = allocated_set = set_new(NULL);
                 if (!s)
                         return -ENOMEM;
         }
@@ -239,7 +239,7 @@ int cg_kill_recursive(const char *controller, const char *path, int sig, bool si
         assert(sig >= 0);
 
         if (!s) {
-                s = allocated_set = set_new(trivial_hash_func, trivial_compare_func);
+                s = allocated_set = set_new(NULL);
                 if (!s)
                         return -ENOMEM;
         }
@@ -290,7 +290,7 @@ int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char
         assert(cto);
         assert(pto);
 
-        s = set_new(trivial_hash_func, trivial_compare_func);
+        s = set_new(NULL);
         if (!s)
                 return -ENOMEM;
 
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
index c72a099..e6ee97a 100644
--- a/src/shared/conf-files.c
+++ b/src/shared/conf-files.c
@@ -109,7 +109,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
         if (!path_strv_resolve_uniq(dirs, root))
                 return -ENOMEM;
 
-        fh = hashmap_new(string_hash_func, string_compare_func);
+        fh = hashmap_new(&string_hash_ops);
         if (!fh)
                 return -ENOMEM;
 
diff --git a/src/shared/fdset.c b/src/shared/fdset.c
index d2ea665..37cbd85 100644
--- a/src/shared/fdset.c
+++ b/src/shared/fdset.c
@@ -38,7 +38,7 @@
 #define PTR_TO_FD(p) (PTR_TO_INT(p)-1)
 
 FDSet *fdset_new(void) {
-        return MAKE_FDSET(set_new(trivial_hash_func, trivial_compare_func));
+        return MAKE_FDSET(set_new(NULL));
 }
 
 void fdset_free(FDSet *s) {
diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
index dbf91c4..715484c 100644
--- a/src/shared/hashmap.c
+++ b/src/shared/hashmap.c
@@ -39,8 +39,7 @@ struct hashmap_entry {
 };
 
 struct Hashmap {
-        hash_func_t hash_func;
-        compare_func_t compare_func;
+        const struct hash_ops *hash_ops;
 
         struct hashmap_entry *iterate_list_head, *iterate_list_tail;
 
@@ -141,6 +140,11 @@ int string_compare_func(const void *a, const void *b) {
         return strcmp(a, b);
 }
 
+const struct hash_ops string_hash_ops = {
+        .hash = string_hash_func,
+        .compare = string_compare_func
+};
+
 unsigned long trivial_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
         uint64_t u;
         siphash24((uint8_t*) &u, &p, sizeof(p), hash_key);
@@ -151,6 +155,11 @@ int trivial_compare_func(const void *a, const void *b) {
         return a < b ? -1 : (a > b ? 1 : 0);
 }
 
+const struct hash_ops trivial_hash_ops = {
+        .hash = trivial_hash_func,
+        .compare = trivial_compare_func
+};
+
 unsigned long uint64_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
         uint64_t u;
         siphash24((uint8_t*) &u, p, sizeof(uint64_t), hash_key);
@@ -164,6 +173,11 @@ int uint64_compare_func(const void *_a, const void *_b) {
         return a < b ? -1 : (a > b ? 1 : 0);
 }
 
+const struct hash_ops uint64_hash_ops = {
+        .hash = uint64_hash_func,
+        .compare = uint64_compare_func
+};
+
 #if SIZEOF_DEV_T != 8
 unsigned long devt_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
         uint64_t u;
@@ -177,10 +191,15 @@ int devt_compare_func(const void *_a, const void *_b) {
         b = *(const dev_t*) _b;
         return a < b ? -1 : (a > b ? 1 : 0);
 }
+
+const struct hash_ops devt_hash_ops = {
+        .hash = devt_hash_func,
+        .compare = devt_compare_func
+};
 #endif
 
 static unsigned bucket_hash(Hashmap *h, const void *p) {
-        return (unsigned) (h->hash_func(p, h->hash_key) % h->n_buckets);
+        return (unsigned) (h->hash_ops->hash(p, h->hash_key) % h->n_buckets);
 }
 
 static void get_hash_key(uint8_t hash_key[HASH_KEY_SIZE], bool reuse_is_ok) {
@@ -202,7 +221,7 @@ static void get_hash_key(uint8_t hash_key[HASH_KEY_SIZE], bool reuse_is_ok) {
         memcpy(hash_key, current, sizeof(current));
 }
 
-Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) {
+Hashmap *hashmap_new(const struct hash_ops *hash_ops) {
         bool b;
         Hashmap *h;
         size_t size;
@@ -224,8 +243,7 @@ Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) {
                         return NULL;
         }
 
-        h->hash_func = hash_func ? hash_func : trivial_hash_func;
-        h->compare_func = compare_func ? compare_func : trivial_compare_func;
+        h->hash_ops = hash_ops ? hash_ops : &trivial_hash_ops;
 
         h->n_buckets = INITIAL_N_BUCKETS;
         h->n_entries = 0;
@@ -240,7 +258,7 @@ Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) {
         return h;
 }
 
-int hashmap_ensure_allocated(Hashmap **h, hash_func_t hash_func, compare_func_t compare_func) {
+int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops) {
         Hashmap *q;
 
         assert(h);
@@ -248,7 +266,7 @@ int hashmap_ensure_allocated(Hashmap **h, hash_func_t hash_func, compare_func_t
         if (*h)
                 return 0;
 
-        q = hashmap_new(hash_func, compare_func);
+        q = hashmap_new(hash_ops);
         if (!q)
                 return -ENOMEM;
 
@@ -406,7 +424,7 @@ static struct hashmap_entry *hash_scan(Hashmap *h, unsigned hash, const void *ke
         assert(hash < h->n_buckets);
 
         for (e = h->buckets[hash]; e; e = e->bucket_next)
-                if (h->compare_func(e->key, key) == 0)
+                if (h->hash_ops->compare(e->key, key) == 0)
                         return e;
 
         return NULL;
@@ -438,7 +456,7 @@ static bool resize_buckets(Hashmap *h) {
         for (i = h->iterate_list_head; i; i = i->iterate_next) {
                 unsigned long old_bucket, new_bucket;
 
-                old_bucket = h->hash_func(i->key, h->hash_key) % h->n_buckets;
+                old_bucket = h->hash_ops->hash(i->key, h->hash_key) % h->n_buckets;
 
                 /* First, drop from old bucket table */
                 if (i->bucket_next)
@@ -450,7 +468,7 @@ static bool resize_buckets(Hashmap *h) {
                         h->buckets[old_bucket] = i->bucket_next;
 
                 /* Then, add to new backet table */
-                new_bucket = h->hash_func(i->key, nkey)  % m;
+                new_bucket = h->hash_ops->hash(i->key, nkey) % m;
 
                 i->bucket_next = n[new_bucket];
                 i->bucket_previous = NULL;
@@ -949,7 +967,7 @@ Hashmap *hashmap_copy(Hashmap *h) {
 
         assert(h);
 
-        copy = hashmap_new(h->hash_func, h->compare_func);
+        copy = hashmap_new(h->hash_ops);
         if (!copy)
                 return NULL;
 
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
index f89e7e8..7385ebc 100644
--- a/src/shared/hashmap.h
+++ b/src/shared/hashmap.h
@@ -43,38 +43,50 @@ 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;
 
 /* 32bit values we can always just embedd in the pointer itself, but
  * in order to support 32bit archs we need store 64bit values
  * indirectly, since they don't fit in a pointer. */
 unsigned long uint64_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
 int uint64_compare_func(const void *a, const void *b) _pure_;
+extern const struct hash_ops uint64_hash_ops;
 
 /* On some archs dev_t is 32bit, and on others 64bit. And sometimes
  * it's 64bit on 32bit archs, and sometimes 32bit on 64bit archs. Yuck! */
 #if SIZEOF_DEV_T != 8
 unsigned long devt_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
 int devt_compare_func(const void *a, const void *b) _pure_;
+extern const struct hash_ops devt_hash_ops = {
+        .hash = devt_hash_func,
+        .compare = devt_compare_func
+};
 #else
-/* No need to define a second version of this... */
 #define devt_hash_func uint64_hash_func
 #define devt_compare_func uint64_compare_func
+#define devt_hash_ops uint64_hash_ops
 #endif
 
-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);
 void hashmap_free_free_free(Hashmap *h);
 Hashmap *hashmap_copy(Hashmap *h);
-int hashmap_ensure_allocated(Hashmap **h, hash_func_t hash_func, compare_func_t compare_func);
+int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops);
 
 int hashmap_put(Hashmap *h, const void *key, void *value);
 int hashmap_update(Hashmap *h, const void *key, void *value);
diff --git a/src/shared/install.c b/src/shared/install.c
index 3ef995a..5d3fcf5 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -179,7 +179,7 @@ static int mark_symlink_for_removal(
 
         assert(p);
 
-        r = set_ensure_allocated(remove_symlinks_to, string_hash_func, string_compare_func);
+        r = set_ensure_allocated(remove_symlinks_to, &string_hash_ops);
         if (r < 0)
                 return r;
 
@@ -884,7 +884,7 @@ static int install_info_add(
             hashmap_get(c->will_install, name))
                 return 0;
 
-        r = hashmap_ensure_allocated(&c->will_install, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&c->will_install, &string_hash_ops);
         if (r < 0)
                 return r;
 
@@ -1393,7 +1393,7 @@ static int install_context_apply(
 
         while ((i = hashmap_first(c->will_install))) {
 
-                q = hashmap_ensure_allocated(&c->have_installed, string_hash_func, string_compare_func);
+                q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
                 if (q < 0)
                         return q;
 
@@ -1434,7 +1434,7 @@ static int install_context_mark_for_removal(
 
         while ((i = hashmap_first(c->will_install))) {
 
-                q = hashmap_ensure_allocated(&c->have_installed, string_hash_func, string_compare_func);
+                q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
                 if (q < 0)
                         return q;
 
diff --git a/src/shared/locale-util.c b/src/shared/locale-util.c
index 8d2c363..68851ae 100644
--- a/src/shared/locale-util.c
+++ b/src/shared/locale-util.c
@@ -160,7 +160,7 @@ int get_locales(char ***ret) {
         _cleanup_strv_free_ char **l = NULL;
         int r;
 
-        locales = set_new(string_hash_func, string_compare_func);
+        locales = set_new(&string_hash_ops);
         if (!locales)
                 return -ENOMEM;
 
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 5538dd3..5a7bbaf 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -695,7 +695,7 @@ static int output_json(
                         sd_id128_to_string(boot_id, sid));
         }
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         if (!h)
                 return -ENOMEM;
 
diff --git a/src/shared/set.c b/src/shared/set.c
index 02ea831..d4ffe05 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -30,8 +30,8 @@
 
 /* For now this is not much more than a wrapper around a hashmap */
 
-Set *set_new(hash_func_t hash_func, compare_func_t compare_func) {
-        return MAKE_SET(hashmap_new(hash_func, compare_func));
+Set *set_new(const struct hash_ops *hash_ops) {
+        return MAKE_SET(hashmap_new(hash_ops));
 }
 
 void set_free(Set* s) {
@@ -42,8 +42,8 @@ void set_free_free(Set *s) {
         hashmap_free_free(MAKE_HASHMAP(s));
 }
 
-int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func) {
-        return hashmap_ensure_allocated((Hashmap**) s, hash_func, compare_func);
+int set_ensure_allocated(Set **s, const struct hash_ops *hash_ops) {
+        return hashmap_ensure_allocated((Hashmap**) s, hash_ops);
 }
 
 int set_put(Set *s, void *value) {
diff --git a/src/shared/set.h b/src/shared/set.h
index e0b9c9e..e650b7e 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -32,12 +32,12 @@
 
 typedef struct Set Set;
 
-Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
+Set *set_new(const struct hash_ops *hash_ops);
 void set_free(Set* s);
 void set_free_free(Set *s);
 
 Set* set_copy(Set *s);
-int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
+int set_ensure_allocated(Set **s, const struct hash_ops *hash_ops);
 
 int set_put(Set *s, void *value);
 int set_consume(Set *s, void *value);
diff --git a/src/shared/util.c b/src/shared/util.c
index 502b367..61d6680 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3911,7 +3911,7 @@ void execute_directory(const char *directory, DIR *d, usec_t timeout, char *argv
                         }
                 }
 
-                pids = hashmap_new(NULL, NULL);
+                pids = hashmap_new(NULL);
                 if (!pids) {
                         log_oom();
                         _exit(EXIT_FAILURE);
@@ -6694,7 +6694,7 @@ int bind_remount_recursive(const char *prefix, bool ro) {
 
         path_kill_slashes(cleaned);
 
-        done = set_new(string_hash_func, string_compare_func);
+        done = set_new(&string_hash_ops);
         if (!done)
                 return -ENOMEM;
 
@@ -6704,7 +6704,7 @@ int bind_remount_recursive(const char *prefix, bool ro) {
                 bool top_autofs = false;
                 char *x;
 
-                todo = set_new(string_hash_func, string_compare_func);
+                todo = set_new(&string_hash_ops);
                 if (!todo)
                         return -ENOMEM;
 
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index f6e6672..81d8457 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -473,7 +473,7 @@ static int add_connection_socket(Context *context, int fd) {
                 return 0;
         }
 
-        r = set_ensure_allocated(&context->connections, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&context->connections, NULL);
         if (r < 0) {
                 log_oom();
                 return 0;
@@ -543,7 +543,7 @@ static int add_listen_socket(Context *context, int fd) {
         assert(context);
         assert(fd >= 0);
 
-        r = set_ensure_allocated(&context->listen, trivial_hash_func, trivial_compare_func);
+        r = set_ensure_allocated(&context->listen, NULL);
         if (r < 0) {
                 log_oom();
                 return r;
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 8ce9870..4f9530b 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -292,7 +292,7 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        sysctl_options = hashmap_new(string_hash_func, string_compare_func);
+        sysctl_options = hashmap_new(&string_hash_ops);
         if (!sysctl_options) {
                 r = log_oom();
                 goto finish;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index de43c87..88be871 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -594,7 +594,7 @@ static int get_unit_list_recursive(
         assert(_unit_infos);
         assert(_machines);
 
-        replies = set_new(NULL, NULL);
+        replies = set_new(NULL);
         if (!replies)
                 return log_oom();
 
@@ -1338,7 +1338,7 @@ static int list_unit_files(sd_bus *bus, char **args) {
                 Iterator i;
                 unsigned n_units;
 
-                h = hashmap_new(string_hash_func, string_compare_func);
+                h = hashmap_new(&string_hash_ops);
                 if (!h)
                         return log_oom();
 
@@ -2746,7 +2746,7 @@ static int start_unit(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                s = set_new(string_hash_func, string_compare_func);
+                s = set_new(&string_hash_ops);
                 if (!s)
                         return log_oom();
         }
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index b889ed0..ba20d94 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -107,11 +107,11 @@ static int load_user_database(void) {
         if (!f)
                 return errno == ENOENT ? 0 : -errno;
 
-        r = hashmap_ensure_allocated(&database_user, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&database_user, &string_hash_ops);
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&database_uid, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&database_uid, NULL);
         if (r < 0)
                 return r;
 
@@ -159,11 +159,11 @@ static int load_group_database(void) {
         if (!f)
                 return errno == ENOENT ? 0 : -errno;
 
-        r = hashmap_ensure_allocated(&database_group, string_hash_func, string_compare_func);
+        r = hashmap_ensure_allocated(&database_group, &string_hash_ops);
         if (r < 0)
                 return r;
 
-        r = hashmap_ensure_allocated(&database_gid, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&database_gid, NULL);
         if (r < 0)
                 return r;
 
@@ -969,7 +969,7 @@ static int add_user(Item *i) {
                 i->uid = search_uid;
         }
 
-        r = hashmap_ensure_allocated(&todo_uids, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&todo_uids, NULL);
         if (r < 0)
                 return log_oom();
 
@@ -1122,7 +1122,7 @@ static int add_group(Item *i) {
                 i->gid = search_uid;
         }
 
-        r = hashmap_ensure_allocated(&todo_gids, trivial_hash_func, trivial_compare_func);
+        r = hashmap_ensure_allocated(&todo_gids, NULL);
         if (r < 0)
                 return log_oom();
 
@@ -1210,7 +1210,7 @@ static int add_implicit(void) {
                 if (!i) {
                         _cleanup_(item_freep) Item *j = NULL;
 
-                        r = hashmap_ensure_allocated(&groups, string_hash_func, string_compare_func);
+                        r = hashmap_ensure_allocated(&groups, &string_hash_ops);
                         if (r < 0)
                                 return log_oom();
 
@@ -1237,7 +1237,7 @@ static int add_implicit(void) {
                         if (!i) {
                                 _cleanup_(item_freep) Item *j = NULL;
 
-                                r = hashmap_ensure_allocated(&users, string_hash_func, string_compare_func);
+                                r = hashmap_ensure_allocated(&users, &string_hash_ops);
                                 if (r < 0)
                                         return log_oom();
 
@@ -1542,7 +1542,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                         return -EINVAL;
                 }
 
-                r = hashmap_ensure_allocated(&members, string_hash_func, string_compare_func);
+                r = hashmap_ensure_allocated(&members, &string_hash_ops);
                 if (r < 0)
                         return log_oom();
 
@@ -1584,7 +1584,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                         return -EINVAL;
                 }
 
-                r = hashmap_ensure_allocated(&users, string_hash_func, string_compare_func);
+                r = hashmap_ensure_allocated(&users, &string_hash_ops);
                 if (r < 0)
                         return log_oom();
 
@@ -1634,7 +1634,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                         return -EINVAL;
                 }
 
-                r = hashmap_ensure_allocated(&groups, string_hash_func, string_compare_func);
+                r = hashmap_ensure_allocated(&groups, &string_hash_ops);
                 if (r < 0)
                         return log_oom();
 
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index 368d420..6c3281f 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -824,8 +824,7 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
                                                         MAX(a*10 + b, service->sysv_start_priority);
                                         }
 
-                                        r = set_ensure_allocated(&runlevel_services[i],
-                                                                 trivial_hash_func, trivial_compare_func);
+                                        r = set_ensure_allocated(&runlevel_services[i], NULL);
                                         if (r < 0)
                                                 goto finish;
 
@@ -836,8 +835,7 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
                                 } else if (de->d_name[0] == 'K' &&
                                            (rcnd_table[i].type == RUNLEVEL_DOWN)) {
 
-                                        r = set_ensure_allocated(&shutdown_services,
-                                                                 trivial_hash_func, trivial_compare_func);
+                                        r = set_ensure_allocated(&shutdown_services, NULL);
                                         if (r < 0)
                                                 goto finish;
 
@@ -905,7 +903,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        all_services = hashmap_new(string_hash_func, string_compare_func);
+        all_services = hashmap_new(&string_hash_ops);
         if (!all_services) {
                 log_oom();
                 return EXIT_FAILURE;
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
index ccef61f..95a7f83 100644
--- a/src/test/test-hashmap.c
+++ b/src/test/test-hashmap.c
@@ -26,7 +26,7 @@ static void test_hashmap_replace(void) {
         Hashmap *m;
         char *val1, *val2, *val3, *val4, *val5, *r;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         val1 = strdup("val1");
         assert_se(val1);
@@ -73,7 +73,7 @@ static void test_hashmap_copy(void) {
         val4 = strdup("val4");
         assert_se(val4);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "key 1", val1);
         hashmap_put(m, "key 2", val2);
@@ -109,7 +109,7 @@ static void test_hashmap_get_strv(void) {
         val4 = strdup("val4");
         assert_se(val4);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "key 1", val1);
         hashmap_put(m, "key 2", val2);
@@ -141,8 +141,8 @@ static void test_hashmap_move_one(void) {
         val4 = strdup("val4");
         assert_se(val4);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
-        n = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
+        n = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "key 1", val1);
         hashmap_put(m, "key 2", val2);
@@ -168,7 +168,7 @@ static void test_hashmap_next(void) {
         Hashmap *m;
         char *val1, *val2, *val3, *val4, *r;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         val1 = strdup("val1");
         assert_se(val1);
         val2 = strdup("val2");
@@ -199,7 +199,7 @@ static void test_hashmap_update(void) {
         Hashmap *m;
         char *val1, *val2, *r;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         val1 = strdup("old_value");
         assert_se(val1);
         val2 = strdup("new_value");
@@ -222,7 +222,7 @@ static void test_hashmap_put(void) {
         Hashmap *m;
         int valid_hashmap_put;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         valid_hashmap_put = hashmap_put(m, "key 1", (void*) (const char *) "val 1");
         assert_se(valid_hashmap_put == 1);
@@ -236,7 +236,7 @@ static void test_hashmap_remove_and_put(void) {
         int valid;
         char *r;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         assert_se(m);
 
         valid = hashmap_remove_and_put(m, "unvalid key", "new key", NULL);
@@ -261,9 +261,9 @@ static void test_hashmap_ensure_allocated(void) {
         Hashmap *m;
         int valid_hashmap;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
-        valid_hashmap = hashmap_ensure_allocated(&m, string_hash_func, string_compare_func);
+        valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops);
         assert_se(valid_hashmap == 0);
 
         assert_se(m);
@@ -282,7 +282,7 @@ static void test_hashmap_foreach_key(void) {
                 "key 3\0"
                 "key 4\0";
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         NULSTR_FOREACH(key, key_table)
                 hashmap_put(m, key, (void*) (const char*) "my dummy val");
@@ -319,7 +319,7 @@ static void test_hashmap_foreach(void) {
         val4 = strdup("my val4");
         assert_se(val4);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "Key 1", val1);
         hashmap_put(m, "Key 2", val2);
@@ -358,7 +358,7 @@ static void test_hashmap_foreach_backwards(void) {
         val4 = strdup("my val4");
         assert_se(val4);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         hashmap_put(m, "Key 1", val1);
         hashmap_put(m, "Key 2", val2);
         hashmap_put(m, "Key 3", val3);
@@ -395,8 +395,8 @@ static void test_hashmap_merge(void) {
         val4 = strdup("my val4");
         assert_se(val4);
 
-        n = hashmap_new(string_hash_func, string_compare_func);
-        m = hashmap_new(string_hash_func, string_compare_func);
+        n = hashmap_new(&string_hash_ops);
+        m = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "Key 1", val1);
         hashmap_put(m, "Key 2", val2);
@@ -422,7 +422,7 @@ static void test_hashmap_contains(void) {
         val1 = strdup("my val");
         assert_se(val1);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         assert_se(!hashmap_contains(m, "Key 1"));
         hashmap_put(m, "Key 1", val1);
@@ -439,7 +439,7 @@ static void test_hashmap_isempty(void) {
         val1 = strdup("my val");
         assert_se(val1);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         assert_se(hashmap_isempty(m));
         hashmap_put(m, "Key 1", val1);
@@ -462,7 +462,7 @@ static void test_hashmap_size(void) {
         val4 = strdup("my val");
         assert_se(val4);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "Key 1", val1);
         hashmap_put(m, "Key 2", val2);
@@ -482,7 +482,7 @@ static void test_hashmap_get(void) {
         val = strdup("my val");
         assert_se(val);
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
 
         hashmap_put(m, "Key 1", val);
 
@@ -499,7 +499,7 @@ static void test_hashmap_many(void) {
 
 #define N_ENTRIES 100000
 
-        assert_se(h = hashmap_new(NULL, NULL));
+        assert_se(h = hashmap_new(NULL));
 
         for (i = 1; i < N_ENTRIES*3; i+=3) {
                 assert_se(hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0);
@@ -520,7 +520,7 @@ static void test_hashmap_many(void) {
 static void test_hashmap_first_key(void) {
         _cleanup_hashmap_free_ Hashmap *m = NULL;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         assert_se(m);
 
         assert_se(!hashmap_first_key(m));
@@ -535,7 +535,7 @@ static void test_hashmap_first_key(void) {
 static void test_hashmap_last(void) {
         _cleanup_hashmap_free_ Hashmap *m = NULL;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         assert_se(m);
 
         assert_se(!hashmap_last(m));
@@ -550,7 +550,7 @@ static void test_hashmap_last(void) {
 static void test_hashmap_steal_first_key(void) {
         _cleanup_hashmap_free_ Hashmap *m = NULL;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         assert_se(m);
 
         assert_se(!hashmap_steal_first_key(m));
@@ -563,7 +563,7 @@ static void test_hashmap_steal_first_key(void) {
 static void test_hashmap_clear_free_free(void) {
         _cleanup_hashmap_free_ Hashmap *m = NULL;
 
-        m = hashmap_new(string_hash_func, string_compare_func);
+        m = hashmap_new(&string_hash_ops);
         assert_se(m);
 
         assert_se(hashmap_put(m, strdup("key 1"), NULL) == 1);
diff --git a/src/test/test-install.c b/src/test/test-install.c
index 099eb40..b0f77a1 100644
--- a/src/test/test-install.c
+++ b/src/test/test-install.c
@@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {
         UnitFileChange *changes = NULL;
         unsigned n_changes = 0;
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
         assert_se(r == 0);
 
diff --git a/src/test/test-prioq.c b/src/test/test-prioq.c
index cdb1e4a..dfedc9b 100644
--- a/src/test/test-prioq.c
+++ b/src/test/test-prioq.c
@@ -98,6 +98,11 @@ static unsigned long test_hash(const void *a, const uint8_t hash_key[HASH_KEY_SI
         return (unsigned long) u;
 }
 
+static const struct hash_ops test_hash_ops = {
+        .hash = test_hash,
+        .compare = test_compare
+};
+
 static void test_struct(void) {
         Prioq *q;
         Set *s;
@@ -109,7 +114,7 @@ static void test_struct(void) {
         q = prioq_new(test_compare);
         assert_se(q);
 
-        s = set_new(test_hash, test_compare);
+        s = set_new(&test_hash_ops);
         assert_se(s);
 
         for (i = 0; i < SET_SIZE; i++) {
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index 3486572..89f5bdd 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -44,7 +44,7 @@ static int test_unit_file_get_set(void) {
         Iterator i;
         UnitFileList *p;
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         assert(h);
 
         r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 3bab7ac..f9830c4 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -165,7 +165,7 @@ static void load_unix_sockets(void) {
         /* We maintain a cache of the sockets we found in
          * /proc/net/unix to speed things up a little. */
 
-        unix_sockets = set_new(string_hash_func, string_compare_func);
+        unix_sockets = set_new(&string_hash_ops);
         if (!unix_sockets)
                 return;
 
@@ -1608,8 +1608,8 @@ int main(int argc, char *argv[]) {
 
         label_init(NULL);
 
-        items = hashmap_new(string_hash_func, string_compare_func);
-        globs = hashmap_new(string_hash_func, string_compare_func);
+        items = hashmap_new(&string_hash_ops);
+        globs = hashmap_new(&string_hash_ops);
 
         if (!items || !globs) {
                 r = log_oom();

commit f44541bc934c6e2b02155559e9eeb17a13a09558
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Fri Aug 15 16:33:03 2014 +0200

    build: colorize gcc only if on tty
    
    Rather than forcing gcc to always produce colorized error messages
    whether on tty or not, enable automatic colorization by ensuring
    GCC_COLORS is set to a non-empty string.
    
    Doing it this way removes the need for workarounds in ~/.emacs or
    ~/.vimrc for "M-x compile" or ":make", respectively, to work.

diff --git a/Makefile.am b/Makefile.am
index de40043..5dc17f8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,9 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 AM_MAKEFLAGS = --no-print-directory
 AUTOMAKE_OPTIONS = color-tests parallel-tests
 
+GCC_COLORS ?= 'ooh, shiny!'
+export GCC_COLORS
+
 SUBDIRS = . po
 
 # remove targets if the command fails
diff --git a/configure.ac b/configure.ac
index 99c01d2..fb16904 100644
--- a/configure.ac
+++ b/configure.ac
@@ -190,7 +190,6 @@ CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
         -ffast-math \
         -fno-common \
         -fdiagnostics-show-option \
-        -fdiagnostics-color \
         -fno-strict-aliasing \
         -fvisibility=hidden \
         -ffunction-sections \



More information about the systemd-commits mailing list