chiark / gitweb /
hashmap: introduce hash_ops to make struct Hashmap smaller
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 12 Aug 2014 23:00:18 +0000 (01:00 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Mon, 15 Sep 2014 14:08:50 +0000 (16:08 +0200)
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.

82 files changed:
src/analyze/analyze.c
src/bus-proxyd/bus-policy.c
src/cgtop/cgtop.c
src/core/automount.c
src/core/bus-endpoint.c
src/core/dbus-manager.c
src/core/dbus.c
src/core/device.c
src/core/killall.c
src/core/load-fragment.c
src/core/manager.c
src/core/mount-setup.c
src/core/swap.c
src/core/transaction.c
src/core/unit.c
src/delta/delta.c
src/journal-remote/journal-remote.c
src/journal/catalog.c
src/journal/catalog.h
src/journal/coredump-vacuum.c
src/journal/coredumpctl.c
src/journal/journal-file.c
src/journal/journalctl.c
src/journal/journald-server.c
src/journal/mmap-cache.c
src/journal/sd-journal.c
src/journal/test-catalog.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd/sd-bus/bus-match.c
src/libsystemd/sd-bus/bus-objects.c
src/libsystemd/sd-bus/bus-track.c
src/libsystemd/sd-bus/bus-util.c
src/libsystemd/sd-bus/busctl.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-rtnl/sd-rtnl.c
src/locale/localectl.c
src/login/logind-acl.c
src/login/logind-session.c
src/login/logind.c
src/machine/machined.c
src/network/networkd-link.c
src/network/networkd-manager.c
src/network/networkd-network.c
src/network/networkd-wait-online-link.c
src/readahead/readahead-collect.c
src/remount-fs/remount-fs.c
src/resolve/resolved-dns-cache.c
src/resolve/resolved-dns-domain.c
src/resolve/resolved-dns-domain.h
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-rr.c
src/resolve/resolved-dns-rr.h
src/resolve/resolved-dns-scope.c
src/resolve/resolved-dns-server.c
src/resolve/resolved-dns-server.h
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-dns-zone.c
src/resolve/resolved-link.c
src/resolve/resolved-manager.c
src/shared/cgroup-util.c
src/shared/conf-files.c
src/shared/fdset.c
src/shared/hashmap.c
src/shared/hashmap.h
src/shared/install.c
src/shared/locale-util.c
src/shared/logs-show.c
src/shared/set.c
src/shared/set.h
src/shared/util.c
src/socket-proxy/socket-proxyd.c
src/sysctl/sysctl.c
src/systemctl/systemctl.c
src/sysusers/sysusers.c
src/sysv-generator/sysv-generator.c
src/test/test-hashmap.c
src/test/test-install.c
src/test/test-prioq.c
src/test/test-unit-file.c
src/tmpfiles/tmpfiles.c

index 82f5cf3c57d044c41b50d6c046b8fe45bdff838c..5e55988063585b2a93662baedeb4082d149941eb 100644 (file)
@@ -907,7 +907,7 @@ static int analyze_critical_chain(sd_bus *bus, char *names[]) {
         if (n <= 0)
                 return n;
 
         if (n <= 0)
                 return n;
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         if (!h)
                 return -ENOMEM;
 
         if (!h)
                 return -ENOMEM;
 
index 06c16a7eb6d2ca7ee29b9b4540bc22d679a43219..d2eace940512645089192da8ae460fcddb197c6f 100644 (file)
@@ -338,7 +338,7 @@ static int file_load(Policy *p, const char *path) {
 
                                         assert_cc(sizeof(uid_t) == sizeof(uint32_t));
 
 
                                         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();
 
                                         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));
 
 
                                         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();
 
                                         if (r < 0)
                                                 return log_oom();
 
index 509fe4cdc8341a89155494ffdb37ce39cb923221..ab8c4cfda1cfcc6678bd9a5a0a3fc4210ec27226 100644 (file)
@@ -695,8 +695,8 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 goto finish;
 
         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;
         if (!a || !b) {
                 r = log_oom();
                 goto finish;
index 73a8ce17e4a7052e1e29c38cfdcb08696b7ac064..f72aca29579aea9bf61f5a9a3d25df329c88e536 100644 (file)
@@ -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)
                         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));
                                         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);
 
                 } 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;
                 if (r < 0) {
                         log_error_unit(UNIT(a)->id, "Failed to allocate token set.");
                         goto fail;
index 8d11974db484e81227de2f781d8598b8b1b85b11..1e8f07eb54c10d9e64887a4bd0afb2e788b43f0f 100644 (file)
@@ -55,7 +55,7 @@ int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess a
                         return 0;
                 }
         } else {
                         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;
         }
                 if (!ep->policy_hash)
                         return -ENOMEM;
         }
index 2fe9d193f6a79f1715676303a352a4e71befd9fb..533ce439a77013fedd42c80f4162bb05bebe0736 100644 (file)
@@ -1399,7 +1399,7 @@ static int method_list_unit_files(sd_bus *bus, sd_bus_message *message, void *us
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        h = hashmap_new(string_hash_func, string_compare_func);
+        h = hashmap_new(&string_hash_ops);
         if (!h)
                 return -ENOMEM;
 
         if (!h)
                 return -ENOMEM;
 
index e7eee3c6d1ef3c132df824a9851fefdb96f7ae21..09b4a4ac6ffc603cc7ed37d24e460b886da440d0 100644 (file)
@@ -659,7 +659,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
                 return 0;
         }
 
                 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;
         if (r < 0) {
                 log_oom();
                 return 0;
index 0f28a168740de09d95bb46c2cbc4165ea11d604a..11c426108151f9a81b132d9cea76c29ccb7b4d97 100644 (file)
@@ -304,7 +304,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
                         goto fail;
                 }
 
                         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;
 
                 if (r < 0)
                         goto fail;
 
@@ -517,7 +517,7 @@ static int device_following_set(Unit *u, Set **_set) {
                 return 0;
         }
 
                 return 0;
         }
 
-        set = set_new(NULL, NULL);
+        set = set_new(NULL);
         if (!set)
                 return -ENOMEM;
 
         if (!set)
                 return -ENOMEM;
 
index 291e1f90eeb192be472f2faf876a04c4e0521093..a6ff50a5a4a56fdcdcbbedac17ecfc3d23d2f6c7 100644 (file)
@@ -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)
         _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);
 
         assert_se(sigemptyset(&mask) == 0);
         assert_se(sigaddset(&mask, SIGCHLD) == 0);
index 7cf19b93ccb847a34ea320e4475bc240e2d025a2..0620882b4ed04fbbc105e4ba6843a04096ac3b58 100644 (file)
@@ -2276,7 +2276,7 @@ int config_parse_syscall_filter(
         }
 
         if (!c->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();
 
                 if (!c->syscall_filter)
                         return log_oom();
 
@@ -2368,7 +2368,7 @@ int config_parse_syscall_archs(
                 return 0;
         }
 
                 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();
 
         if (r < 0)
                 return log_oom();
 
@@ -2474,7 +2474,7 @@ int config_parse_address_families(
         }
 
         if (!c->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();
 
                 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();
 
                 if (r < 0)
                         return log_oom();
 
@@ -3423,7 +3423,7 @@ static int load_from_path(Unit *u, const char *path) {
         assert(u);
         assert(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;
 
         if (!symlink_names)
                 return -ENOMEM;
 
index 095111e8c656f93b0ea5fdd876e8bfb1b0a641e2..0770727cde6651bf51758ab60a596b36829e2f89 100644 (file)
@@ -449,27 +449,27 @@ int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) {
         if (r < 0)
                 goto fail;
 
         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;
 
         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;
 
         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;
 
         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;
 
         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;
 
         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;
 
         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);
 
 
         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;
         if (!m->unit_path_cache) {
                 log_error("Failed to allocate unit path cache.");
                 return;
index cc2633e3bd2c02d1e09a2dd9a2628b830d536f39..23a66d2e957a5fc5d4f50870791a082ea7108cd8 100644 (file)
@@ -235,7 +235,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
                 return 0;
         }
 
                 return 0;
         }
 
-        controllers = set_new(string_hash_func, string_compare_func);
+        controllers = set_new(&string_hash_ops);
         if (!controllers)
                 return log_oom();
 
         if (!controllers)
                 return log_oom();
 
index 019d32ed0d607afde9eaa06571156e68388f65b8..b88a914f72b9138b499cba2d374a502d9cdce858 100644 (file)
@@ -77,7 +77,7 @@ static int swap_set_devnode(Swap *s, const char *devnode) {
 
         assert(s);
 
 
         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;
 
         if (r < 0)
                 return r;
 
@@ -1226,7 +1226,7 @@ static int swap_following_set(Unit *u, Set **_set) {
                 return 0;
         }
 
                 return 0;
         }
 
-        set = set_new(NULL, NULL);
+        set = set_new(NULL);
         if (!set)
                 return -ENOMEM;
 
         if (!set)
                 return -ENOMEM;
 
index 1f4c9ce416da2c110911b48af86305602858b2f0..dbb4133fe38f853f893a3c90b72082002414e7d8 100644 (file)
@@ -1143,7 +1143,7 @@ Transaction *transaction_new(bool irreversible) {
         if (!tr)
                 return NULL;
 
         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;
         if (!tr->jobs) {
                 free(tr);
                 return NULL;
index b5c3182940505a0831e8826d54f74c5ce495e5b2..5978e21f56d06059775ad923d02b33c9ba9f7492 100644 (file)
@@ -81,7 +81,7 @@ Unit *unit_new(Manager *m, size_t size) {
         if (!u)
                 return NULL;
 
         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;
         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. */
 
         /* 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;
 
         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) {
         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;
 
                 if (r < 0)
                         return r;
 
@@ -2086,22 +2086,22 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
                 return 0;
         }
 
                 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) {
         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) {
                 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;
 
                 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;
         }
                 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;
 
         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;
 
         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) {
                         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;
                         }
                                 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;
 
                         if (!q)
                                 return -ENOMEM;
 
-                        x = set_new(NULL, NULL);
+                        x = set_new(NULL);
                         if (!x) {
                                 free(q);
                                 return -ENOMEM;
                         if (!x) {
                                 free(q);
                                 return -ENOMEM;
index cd8bd35716f994a9f3d03bd85c0b1837401bd7d9..91f8592b40941d9729378eda932789a2f7092d5d 100644 (file)
@@ -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_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);
                         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);
 
 
         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;
         if (!top || !bottom || !drops) {
                 r = -ENOMEM;
                 goto finish;
index 1cc86aeaf3bf17a87e7da57357d1a70acf4d3ac2..12de8203306b21849ed94412226b551149f79877 100644 (file)
@@ -222,20 +222,14 @@ static int open_output(Writer *w, const char* host) {
  **********************************************************************/
 
 static int init_writer_hashmap(RemoteServer *s) {
  **********************************************************************/
 
 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();
 
         if (!s->writers)
                 return log_oom();
 
@@ -695,7 +689,7 @@ static int setup_microhttpd_server(RemoteServer *s,
                 goto error;
         }
 
                 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;
         if (r < 0) {
                 log_oom();
                 goto error;
index f03357dedf9bc87ca84a28873d7e330282eae981..41d450b1544d6fbf2e8e140e016b2b42c2625cc2 100644 (file)
@@ -64,7 +64,7 @@ typedef struct CatalogItem {
         le64_t offset;
 } 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;
         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;
 }
 
         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;
 
         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);
 }
 
         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,
 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;
 
         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) {
         sb = strbuf_new();
 
         if (!h || !sb) {
index fdde67aeedd87462ee4311bdcdd1afbea02c387f..a72ecf6de7d04a630d8805976989041b5585bbbf 100644 (file)
 #include "strbuf.h"
 
 int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path);
 #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[];
 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;
index 125bb3a4b899e32acf24ca8b57089ed7657afa6c..fec901e8e44f2dddf845eb86c9bf398033bffa0a 100644 (file)
@@ -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;
 
                             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();
 
                         if (r < 0)
                                 return log_oom();
 
index 34dcae87c0c48b8e2395c2bec3d40358735e8961..d4756fe67dcd8761ce79791dc287262a6472277c 100644 (file)
@@ -58,7 +58,7 @@ static Set *new_matches(void) {
         char *tmp;
         int r;
 
         char *tmp;
         int r;
 
-        set = set_new(trivial_hash_func, trivial_compare_func);
+        set = set_new(NULL);
         if (!set) {
                 log_oom();
                 return NULL;
         if (!set) {
                 log_oom();
                 return NULL;
index 7286e14ddba32a07421a15a7b2c451b74b379c53..f25cda6ddca76c49f582cc81272d8fe3f3f28720 100644 (file)
@@ -2498,7 +2498,7 @@ int journal_file_open(
                 goto fail;
         }
 
                 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;
         if (!f->chain_cache) {
                 r = -ENOMEM;
                 goto fail;
index d00a815ba9ce3d06fe934de026c36520f6782cdb..47206d383a92f560ab9f4fb8839ceaf06739d550 100644 (file)
@@ -1029,7 +1029,7 @@ static int get_possible_units(sd_journal *j,
         const char *field;
         int r;
 
         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();
 
         if (!found)
                 return log_oom();
 
index 01da38b8d814473ab0fc24f5c61e26e7a21765fd..3df7416397871f6cbfeffefc26fb1c533fcc1245 100644 (file)
@@ -1483,7 +1483,7 @@ int server_init(Server *s) {
 
         mkdir_p("/run/systemd/journal", 0755);
 
 
         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();
 
         if (!s->user_journals)
                 return log_oom();
 
index 908562da27a45e922f5ddccfe31de12d0934a98b..2d268fc3329156a445856f8f31855469a828b07b 100644 (file)
@@ -227,7 +227,7 @@ static Context *context_add(MMapCache *m, unsigned id) {
         if (c)
                 return c;
 
         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;
 
         if (r < 0)
                 return NULL;
 
@@ -281,7 +281,7 @@ static FileDescriptor* fd_add(MMapCache *m, int fd) {
         if (f)
                 return f;
 
         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;
 
         if (r < 0)
                 return NULL;
 
index 693707cb347a817da8f2a416e29ba5dfe6d30aa2..1fc9f01d0aa8810f333bf571783190987b14a95d 100644 (file)
@@ -70,7 +70,7 @@ static int set_put_error(sd_journal *j, int r) {
         if (r >= 0)
                 return 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;
 
         if (k < 0)
                 return k;
 
@@ -1662,7 +1662,7 @@ static int allocate_inotify(sd_journal *j) {
         }
 
         if (!j->directories_by_wd) {
         }
 
         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;
         }
                 if (!j->directories_by_wd)
                         return -ENOMEM;
         }
@@ -1688,8 +1688,8 @@ static sd_journal *journal_new(int flags, const char *path) {
                         goto fail;
         }
 
                         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;
         j->mmap = mmap_cache_new();
         if (!j->files || !j->directories_by_path || !j->mmap)
                 goto fail;
index 967ab6756b323c1b887c801558bbf65ed32b3fa0..5fe2f6a2697e6bb65ba264b2c274e297a013293a 100644 (file)
@@ -62,7 +62,7 @@ static void test_catalog_importing(void) {
         Hashmap *h;
         struct strbuf *sb;
 
         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"
         assert_se(sb = strbuf_new());
 
 #define BUF "xxx"
index ab683228b493831073b672befeebb146908c318e..a6d6178e72be1d3bba1080ae5403b910ee283940 100644 (file)
@@ -109,6 +109,11 @@ int client_id_compare_func(const void *_a, const void *_b) {
         return memcmp(a->data, b->data, a->length);
 }
 
         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;
 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->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;
 
         *ret = server;
         server = NULL;
index 88b61a75be5845227b24f01a7df51796e5258949..18afe0f12a0e96d585b8a29e81b3ff3a70cc01ec 100644 (file)
@@ -450,13 +450,13 @@ static int bus_match_add_compare_value(
                 where->child = c;
 
                 if (t == BUS_MATCH_MESSAGE_TYPE) {
                 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)) {
                         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;
                         if (!c->compare.children) {
                                 r = -ENOMEM;
                                 goto fail;
index 3a2de6520ea9e7c2e1914b8e9fbae458a6d91577..81c840f1294accfcb1f0a606eae02069947a88df 100644 (file)
@@ -225,7 +225,7 @@ static int get_child_nodes(
         assert(n);
         assert(_s);
 
         assert(n);
         assert(_s);
 
-        s = set_new(string_hash_func, string_compare_func);
+        s = set_new(&string_hash_ops);
         if (!s)
                 return -ENOMEM;
 
         if (!s)
                 return -ENOMEM;
 
@@ -1420,7 +1420,7 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) {
         if (n)
                 return n;
 
         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;
 
         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);
 }
 
         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,
 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);
 
                       !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;
 
         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;
 
         if (r < 0)
                 return r;
 
index ffa2cf3d75afe21fc0bf1eb3920eaf3a632bc0e1..0a3322a4ee9859251c65af766371fbf97a128e86 100644 (file)
@@ -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);
 
         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;
 
         if (r < 0)
                 return r;
 
index a85d36180e124b1d2802095e15ae0740c95c1646..7c6da60ccabc9212287235dc4dcb6551dcd0f673 100644 (file)
@@ -399,7 +399,7 @@ int bus_verify_polkit_async(
         if (!sender)
                 return -EBADMSG;
 
         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;
 
         if (r < 0)
                 return r;
 
index af71804410d20b53e3dd9a7a132dd3182ad850bd..f06b74505b478d4a34ce3691d2fe07c26f8f100e 100644 (file)
@@ -76,7 +76,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
 
         pager_open_if_enabled();
 
 
         pager_open_if_enabled();
 
-        names = hashmap_new(string_hash_func, string_compare_func);
+        names = hashmap_new(&string_hash_ops);
         if (!names)
                 return log_oom();
 
         if (!names)
                 return log_oom();
 
index 83b3aa1c3c46837f325c72047ab45fc1be3e6252..33b65aba72e30acf1881de19849a62b7a727edef 100644 (file)
@@ -1756,7 +1756,7 @@ _public_ int sd_bus_call_async(
         if (!BUS_IS_OPEN(bus->state))
                 return -ENOTCONN;
 
         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;
 
         if (r < 0)
                 return r;
 
index 985ff2829bdbab1baa8b74fbb479b779d5f93992..b56182dda76ce0d3c6a8defd2f1229b24ebf55ce 100644 (file)
@@ -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);
 
         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;
 
         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);
 
         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;
 
         if (r < 0)
                 return r;
 
index a3f314b95b76b9415b8bbecb5251ff9ecc7e3492..b7f1afe905066bf2b388af097614259fb13c82b5 100644 (file)
@@ -557,7 +557,7 @@ int sd_rtnl_call_async(sd_rtnl *nl,
         assert_return(callback, -EINVAL);
         assert_return(!rtnl_pid_changed(nl), -ECHILD);
 
         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;
 
         if (r < 0)
                 return r;
 
index 2bb0d3b6be4e570dcb49edf3fb0de051c14f8940..bf8b7b2bef991a968c88886f233130f94613209b 100644 (file)
@@ -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;
 
         _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();
 
         if (!keymaps)
                 return log_oom();
 
index b76e16d9062a64a6d3b436c604cca59dba2d1a5e..f7c6f3a4efe17b7dcf1ef07548e275c4bf88cd5b 100644 (file)
@@ -190,7 +190,7 @@ int devnode_acl_all(struct udev *udev,
 
         assert(udev);
 
 
         assert(udev);
 
-        nodes = set_new(string_hash_func, string_compare_func);
+        nodes = set_new(&string_hash_ops);
         if (!nodes)
                 return -ENOMEM;
 
         if (!nodes)
                 return -ENOMEM;
 
index 10a43a4a30a344eb4349d226f11f863a881671bf..eeb58c9031b71d1bce41805cb778e6d4c7890d30 100644 (file)
@@ -61,7 +61,7 @@ Session* session_new(Manager *m, const char *id) {
                 return NULL;
         }
 
                 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);
         if (!s->devices) {
                 free(s->state_file);
                 free(s);
index 1f94a97bd0500bc17c5db2934c6e873067a5a560..f1b6a86298bd5b1237469c8c6f60292da094172b 100644 (file)
@@ -64,17 +64,17 @@ Manager *manager_new(void) {
 
         m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */
 
 
         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)
 
         if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames ||
             !m->user_units || !m->session_units)
index aac670ba78ff6f47a06bfb91aaf843bae493d7fc..71c8189d5f349da5e55d5d1213f095c0c6ef1105 100644 (file)
@@ -44,9 +44,9 @@ Manager *manager_new(void) {
         if (!m)
                 return NULL;
 
         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);
 
         if (!m->machines || !m->machine_units || !m->machine_leaders) {
                 manager_free(m);
index 11ac1307d88ccb85302487a33debcf5745acf99c..9bf1a811c9f973d3fe654fe3f9307ac4edcb9a4e 100644 (file)
@@ -206,7 +206,7 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
         if (r < 0)
                 return -ENOMEM;
 
         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;
 
         if (r < 0)
                 return r;
 
index 1614bc0091cbb7d818b1e19c16e0a001e9bbee34..2213ad717cb97233cbc254be5a90217d18b00078 100644 (file)
@@ -115,7 +115,7 @@ int manager_new(Manager **ret) {
                         return -ENOMEM;
         }
 
                         return -ENOMEM;
         }
 
-        m->netdevs = hashmap_new(string_hash_func, string_compare_func);
+        m->netdevs = hashmap_new(&string_hash_ops);
         if (!m->netdevs)
                 return -ENOMEM;
 
         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 */
         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;
 
         if (!dns)
                 return -ENOMEM;
 
-        ntp = set_new(string_hash_func, string_compare_func);
+        ntp = set_new(&string_hash_ops);
         if (!ntp)
                 return -ENOMEM;
 
         if (!ntp)
                 return -ENOMEM;
 
-        domains = set_new(string_hash_func, string_compare_func);
+        domains = set_new(&string_hash_ops);
         if (!domains)
                 return -ENOMEM;
 
         if (!domains)
                 return -ENOMEM;
 
index a2e27e09103e10b212519f8cb4857be5a9739200..aad99236c4a4c93c51cb1992ddfa8ebfd87552d2 100644 (file)
@@ -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);
 
         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();
 
         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();
 
         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();
 
         if (!network->routes_by_section)
                 return log_oom();
 
index f23c7ceb80c7196d48d83fd164aa018fe9d5935c..268ab676c958b56cb5884bcf8e45d453a35dcc15 100644 (file)
@@ -34,12 +34,11 @@ int link_new(Manager *m, Link **ret, int ifindex, const char *ifname) {
         assert(m);
         assert(ifindex > 0);
 
         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;
 
         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;
 
         if (r < 0)
                 return r;
 
index 1592cc86784ccae245c1ac0d6979e8a0d37101fe..822a803a41dde0f12fe78ce64c4f1c1718ace899 100644 (file)
@@ -282,7 +282,7 @@ static int collect(const char *root) {
                 goto finish;
         }
 
                 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;
         if (!files) {
                 log_error("Failed to allocate set.");
                 r = -ENOMEM;
index 847637a12ca3988e9f3970e2407e4a82bc54570a..cd7cfe7a474a3aa73405cb2179bbd0b2b2eea593 100644 (file)
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
                 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;
         if (!pids) {
                 log_error("Failed to allocate set");
                 goto finish;
index 733ef6348dd105f821062967a5a71e94eef87ebf..33ca4d1a4549fc184b8a53c1e3efb4c291c7bac5 100644 (file)
@@ -186,7 +186,7 @@ static int dns_cache_init(DnsCache *c) {
         if (r < 0)
                 return r;
 
         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;
 
         if (r < 0)
                 return r;
 
index 8ed1ecf0a480cdebac763faab5b4094cfe743490..e1eb3ddfe5a6a7478246f453694bd9f5d663a232 100644 (file)
@@ -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;
 
 int dns_name_equal(const char *x, const char *y) {
         int r, q, k, w;
 
index e674c5d9c5810b1f1fcf161cfb3a2078a4a290d6..0888a7846f78c65e397272c9693eefdf95308896 100644 (file)
@@ -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);
 
 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);
 
 int dns_name_equal(const char *x, const char *y);
 int dns_name_endswith(const char *name, const char *suffix);
index 0d276df8c951bade95c0131c3f899db7512cc904..7375f77481d427cb4769da98372eb67a96e3291b 100644 (file)
@@ -433,9 +433,7 @@ int dns_packet_append_name(DnsPacket *p, const char *name,
                         goto fail;
 
                 if (allow_compression) {
                         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;
 
                         if (r < 0)
                                 goto fail;
 
index 669595d7f93efe0f47db9c0c4c5cc1945f554ff3..f0483c98069f357b72f60a161842527ba8e369a2 100644 (file)
@@ -144,7 +144,7 @@ static int dns_query_add_transaction(DnsQuery *q, DnsScope *s, DnsResourceKey *k
         assert(q);
         assert(s);
 
         assert(q);
         assert(s);
 
-        r = set_ensure_allocated(&q->transactions, NULL, NULL);
+        r = set_ensure_allocated(&q->transactions, NULL);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
@@ -166,7 +166,7 @@ static int dns_query_add_transaction(DnsQuery *q, DnsScope *s, DnsResourceKey *k
                         return r;
         }
 
                         return r;
         }
 
-        r = set_ensure_allocated(&t->queries, NULL, NULL);
+        r = set_ensure_allocated(&t->queries, NULL);
         if (r < 0)
                 goto gc;
 
         if (r < 0)
                 goto gc;
 
index c5f7cb931e2ae5aea1f9ba8306acc239692bccff..fd5ecf413dc76921b3c6f72783ba8b79bf16cf24 100644 (file)
@@ -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));
 }
 
         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;
 
         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;
 }
 
         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;
 
         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;
 }
 
         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;
 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;
index 3222f1f0ee1f8d698f65118228e9121a09c089cf..9d9a89d38343880f89cb872bb689ce1868d2cb76 100644 (file)
@@ -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);
 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);
 
 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);
 
 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;
index 039a754ff06fe4a6a8eda461b7389c167b92b13b..40d59922d16139640983b3ff9ed0efad15219537 100644 (file)
@@ -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. */
 
         /* 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;
         if (r < 0) {
                 log_oom();
                 return r;
index c99768be4fe4f9f20bfebdad9784a781d7f94076..caf06fe4506781945a6f37ad040fc4bd2fcf984f 100644 (file)
@@ -100,7 +100,7 @@ DnsServer* dns_server_free(DnsServer *s)  {
         return NULL;
 }
 
         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;
 
         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;
 }
 
         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)
         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));
 }
 
         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
+};
index f2361a8385b995af0d7aff570159a5d4a9e56208..a438a27763b38bc16dc28c5717bd5d54386a9d40 100644 (file)
@@ -60,5 +60,4 @@ int dns_server_new(
 
 DnsServer* dns_server_free(DnsServer *s);
 
 
 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;
index 990b1f2e43b5a66f1811610228755ffab09cb37b..74b0634142be5fbd9fd141969402c27ac44617be 100644 (file)
@@ -78,7 +78,7 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsQuestion *q) {
         assert(s);
         assert(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;
 
         if (r < 0)
                 return r;
 
index b53e957d761f321b864cad9a13bd11c3207f0141..8098ff5e70cd14878dd206b189efe4843a8739b5 100644 (file)
@@ -126,11 +126,11 @@ static int dns_zone_init(DnsZone *z) {
 
         assert(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;
 
         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;
 
         if (r < 0)
                 return r;
 
@@ -194,7 +194,7 @@ static int dns_zone_item_probe_start(DnsZoneItem *i)  {
                         return r;
         }
 
                         return r;
         }
 
-        r = set_ensure_allocated(&t->zone_items, NULL, NULL);
+        r = set_ensure_allocated(&t->zone_items, NULL);
         if (r < 0)
                 goto gc;
 
         if (r < 0)
                 goto gc;
 
index f47017ced849948da2fb7a2787c2a880859daba8..4def672214b9cda84acc53da255feff75620f8f0 100644 (file)
@@ -33,7 +33,7 @@ int link_new(Manager *m, Link **ret, int ifindex) {
         assert(m);
         assert(ifindex > 0);
 
         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;
 
         if (r < 0)
                 return r;
 
index 00aaffe44899bdcf9efb01372ee03c2ac47ac603..63d7845387bb03c78fb39595dddd0d6ce8a1ac19 100644 (file)
@@ -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 */
         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;
 
         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;
 
         if (!domains)
                 return -ENOMEM;
 
index 00eac642369df6de0c7ee3f47ee104dcab3983ba..da8e8852260a106248e1e1955152fe3e350ca069 100644 (file)
@@ -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) {
          * 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;
         }
                 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) {
         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;
         }
                 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);
 
         assert(cto);
         assert(pto);
 
-        s = set_new(trivial_hash_func, trivial_compare_func);
+        s = set_new(NULL);
         if (!s)
                 return -ENOMEM;
 
         if (!s)
                 return -ENOMEM;
 
index c72a099b5a1bb5b6805e2f11f651bab3ab1786e5..e6ee97a978472662236732c99f48583ae03e817b 100644 (file)
@@ -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;
 
         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;
 
         if (!fh)
                 return -ENOMEM;
 
index d2ea665016b54b49f48d8496af7fa96911560723..37cbd8526cdedc024bf0734178571f5b4a040c95 100644 (file)
@@ -38,7 +38,7 @@
 #define PTR_TO_FD(p) (PTR_TO_INT(p)-1)
 
 FDSet *fdset_new(void) {
 #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) {
 }
 
 void fdset_free(FDSet *s) {
index dbf91c439ef1ad7d9e5b73901acb2d859180b150..715484ce7cf18912adffdd937f21b6b9b2aa1693 100644 (file)
@@ -39,8 +39,7 @@ struct hashmap_entry {
 };
 
 struct Hashmap {
 };
 
 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;
 
 
         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);
 }
 
         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);
 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);
 }
 
         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);
 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);
 }
 
         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;
 #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);
 }
         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) {
 #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) {
 }
 
 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));
 }
 
         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;
         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;
         }
 
                         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;
 
         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;
 }
 
         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);
         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;
 
         if (*h)
                 return 0;
 
-        q = hashmap_new(hash_func, compare_func);
+        q = hashmap_new(hash_ops);
         if (!q)
                 return -ENOMEM;
 
         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)
         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;
                         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;
 
         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)
 
                 /* 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 */
                         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;
 
                 i->bucket_next = n[new_bucket];
                 i->bucket_previous = NULL;
@@ -949,7 +967,7 @@ Hashmap *hashmap_copy(Hashmap *h) {
 
         assert(h);
 
 
         assert(h);
 
-        copy = hashmap_new(h->hash_func, h->compare_func);
+        copy = hashmap_new(h->hash_ops);
         if (!copy)
                 return NULL;
 
         if (!copy)
                 return NULL;
 
index f89e7e8fbccca62735ac084a18e792ea73add28b..7385ebc5fa7ba85e526280d4457924cfe17d19e1 100644 (file)
@@ -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);
 
 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_;
 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_;
 
 /* 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_;
 
 /* 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_;
 
 /* 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
 #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_func uint64_hash_func
 #define devt_compare_func uint64_compare_func
+#define devt_hash_ops uint64_hash_ops
 #endif
 
 #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);
 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);
 
 int hashmap_put(Hashmap *h, const void *key, void *value);
 int hashmap_update(Hashmap *h, const void *key, void *value);
index 3ef995a9285acd661ec22056810d93de97f230d8..5d3fcf5e32bc0ddf2afef1b9ce7c22078d79ebf7 100644 (file)
@@ -179,7 +179,7 @@ static int mark_symlink_for_removal(
 
         assert(p);
 
 
         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;
 
         if (r < 0)
                 return r;
 
@@ -884,7 +884,7 @@ static int install_info_add(
             hashmap_get(c->will_install, name))
                 return 0;
 
             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;
 
         if (r < 0)
                 return r;
 
@@ -1393,7 +1393,7 @@ static int install_context_apply(
 
         while ((i = hashmap_first(c->will_install))) {
 
 
         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;
 
                 if (q < 0)
                         return q;
 
@@ -1434,7 +1434,7 @@ static int install_context_mark_for_removal(
 
         while ((i = hashmap_first(c->will_install))) {
 
 
         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;
 
                 if (q < 0)
                         return q;
 
index 8d2c36303631e6a7226a5a0e6e5c7fa5c47d7323..68851ae13d38b0b40f245d859dea979b93e3f386 100644 (file)
@@ -160,7 +160,7 @@ int get_locales(char ***ret) {
         _cleanup_strv_free_ char **l = NULL;
         int r;
 
         _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;
 
         if (!locales)
                 return -ENOMEM;
 
index 5538dd3b9e17e1dc2e59ca120bf2c68b41b951f8..5a7bbaf03a92fa08dea2310a406f48ba8cf657b4 100644 (file)
@@ -695,7 +695,7 @@ static int output_json(
                         sd_id128_to_string(boot_id, sid));
         }
 
                         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;
 
         if (!h)
                 return -ENOMEM;
 
index 02ea8315934daed162390f70944300bc8b0759e5..d4ffe056d52a0bc7b188e1917a8965252b280753 100644 (file)
@@ -30,8 +30,8 @@
 
 /* For now this is not much more than a wrapper around a hashmap */
 
 
 /* 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) {
 }
 
 void set_free(Set* s) {
@@ -42,8 +42,8 @@ void set_free_free(Set *s) {
         hashmap_free_free(MAKE_HASHMAP(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) {
 }
 
 int set_put(Set *s, void *value) {
index e0b9c9e0a8b8c69b89459e8045c2fbb474bb4549..e650b7e3feee9945c2496b66b56495613459449a 100644 (file)
 
 typedef struct Set Set;
 
 
 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);
 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);
 
 int set_put(Set *s, void *value);
 int set_consume(Set *s, void *value);
index 502b3675b1d543fec6b082b46f317b4ffeb5f58e..61d6680dddfb5c5dabbe9a45b38b7ebe658f9ee6 100644 (file)
@@ -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);
                 if (!pids) {
                         log_oom();
                         _exit(EXIT_FAILURE);
@@ -6694,7 +6694,7 @@ int bind_remount_recursive(const char *prefix, bool ro) {
 
         path_kill_slashes(cleaned);
 
 
         path_kill_slashes(cleaned);
 
-        done = set_new(string_hash_func, string_compare_func);
+        done = set_new(&string_hash_ops);
         if (!done)
                 return -ENOMEM;
 
         if (!done)
                 return -ENOMEM;
 
@@ -6704,7 +6704,7 @@ int bind_remount_recursive(const char *prefix, bool ro) {
                 bool top_autofs = false;
                 char *x;
 
                 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;
 
                 if (!todo)
                         return -ENOMEM;
 
index f6e6672cdfc5da87a5feff8deb3b49c5587d30b1..81d8457fdd6d4dea507d19ee0dd9c56c3e4cb7df 100644 (file)
@@ -473,7 +473,7 @@ static int add_connection_socket(Context *context, int fd) {
                 return 0;
         }
 
                 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;
         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);
 
         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;
         if (r < 0) {
                 log_oom();
                 return r;
index 8ce9870432c1e54772f3a7a0f43ecb4a62286f3b..4f9530baf8aad7c47def14c46dedf434f4ecce0a 100644 (file)
@@ -292,7 +292,7 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
 
         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;
         if (!sysctl_options) {
                 r = log_oom();
                 goto finish;
index de43c879a72227b43f3c52fb7790ab719b66e42f..88be871f326eb16750ec085819caafcd68ae3999 100644 (file)
@@ -594,7 +594,7 @@ static int get_unit_list_recursive(
         assert(_unit_infos);
         assert(_machines);
 
         assert(_unit_infos);
         assert(_machines);
 
-        replies = set_new(NULL, NULL);
+        replies = set_new(NULL);
         if (!replies)
                 return log_oom();
 
         if (!replies)
                 return log_oom();
 
@@ -1338,7 +1338,7 @@ static int list_unit_files(sd_bus *bus, char **args) {
                 Iterator i;
                 unsigned n_units;
 
                 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();
 
                 if (!h)
                         return log_oom();
 
@@ -2746,7 +2746,7 @@ static int start_unit(sd_bus *bus, char **args) {
                         return r;
                 }
 
                         return r;
                 }
 
-                s = set_new(string_hash_func, string_compare_func);
+                s = set_new(&string_hash_ops);
                 if (!s)
                         return log_oom();
         }
                 if (!s)
                         return log_oom();
         }
index b889ed0536dd41b92232e554e6ec6cdaa1c955a6..ba20d949dc5b2aad24df5655980c1309cf07eb1f 100644 (file)
@@ -107,11 +107,11 @@ static int load_user_database(void) {
         if (!f)
                 return errno == ENOENT ? 0 : -errno;
 
         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;
 
         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;
 
         if (r < 0)
                 return r;
 
@@ -159,11 +159,11 @@ static int load_group_database(void) {
         if (!f)
                 return errno == ENOENT ? 0 : -errno;
 
         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;
 
         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;
 
         if (r < 0)
                 return r;
 
@@ -969,7 +969,7 @@ static int add_user(Item *i) {
                 i->uid = search_uid;
         }
 
                 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();
 
         if (r < 0)
                 return log_oom();
 
@@ -1122,7 +1122,7 @@ static int add_group(Item *i) {
                 i->gid = search_uid;
         }
 
                 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();
 
         if (r < 0)
                 return log_oom();
 
@@ -1210,7 +1210,7 @@ static int add_implicit(void) {
                 if (!i) {
                         _cleanup_(item_freep) Item *j = NULL;
 
                 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();
 
                         if (r < 0)
                                 return log_oom();
 
@@ -1237,7 +1237,7 @@ static int add_implicit(void) {
                         if (!i) {
                                 _cleanup_(item_freep) Item *j = NULL;
 
                         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();
 
                                 if (r < 0)
                                         return log_oom();
 
@@ -1542,7 +1542,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                         return -EINVAL;
                 }
 
                         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();
 
                 if (r < 0)
                         return log_oom();
 
@@ -1584,7 +1584,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                         return -EINVAL;
                 }
 
                         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();
 
                 if (r < 0)
                         return log_oom();
 
@@ -1634,7 +1634,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                         return -EINVAL;
                 }
 
                         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();
 
                 if (r < 0)
                         return log_oom();
 
index 368d420df3bb450dd59645cb0e6f9a2cfa512231..6c3281ff1520dcf470fc2366dba47a0b86ac30a9 100644 (file)
@@ -824,8 +824,7 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
                                                         MAX(a*10 + b, service->sysv_start_priority);
                                         }
 
                                                         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;
 
                                         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)) {
 
                                 } 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;
 
                                         if (r < 0)
                                                 goto finish;
 
@@ -905,7 +903,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
                 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;
         if (!all_services) {
                 log_oom();
                 return EXIT_FAILURE;
index ccef61f55c1bb4ca9e75e6b56da873f65d470cd9..95a7f8379d07b15b0700c7e84e155f25f992a309 100644 (file)
@@ -26,7 +26,7 @@ static void test_hashmap_replace(void) {
         Hashmap *m;
         char *val1, *val2, *val3, *val4, *val5, *r;
 
         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);
 
         val1 = strdup("val1");
         assert_se(val1);
@@ -73,7 +73,7 @@ static void test_hashmap_copy(void) {
         val4 = strdup("val4");
         assert_se(val4);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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;
 
         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");
         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;
 
         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");
         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;
 
         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);
 
         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;
 
         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);
         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;
 
         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);
         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";
 
                 "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");
 
         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);
 
         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 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);
 
         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);
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
         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);
 
 
         hashmap_put(m, "Key 1", val);
 
@@ -499,7 +499,7 @@ static void test_hashmap_many(void) {
 
 #define N_ENTRIES 100000
 
 
 #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);
 
         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;
 
 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));
         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;
 
 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));
         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;
 
 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));
         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;
 
 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);
         assert_se(m);
 
         assert_se(hashmap_put(m, strdup("key 1"), NULL) == 1);
index 099eb401d7e55301af642526ff7faa23e3d1f164..b0f77a18f367ae0958ae5eb28ceddb3967f54b87 100644 (file)
@@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {
         UnitFileChange *changes = NULL;
         unsigned n_changes = 0;
 
         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);
 
         r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
         assert_se(r == 0);
 
index cdb1e4ad52df3768253b957373ff9954b5f7f3ba..dfedc9b8dce32000886baec72ddd75a85edcb249 100644 (file)
@@ -98,6 +98,11 @@ static unsigned long test_hash(const void *a, const uint8_t hash_key[HASH_KEY_SI
         return (unsigned long) u;
 }
 
         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;
 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);
 
         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++) {
         assert_se(s);
 
         for (i = 0; i < SET_SIZE; i++) {
index 34865729f29c0b97748f3a4cd6398c58d7f0f608..89f5bdd4ed3e1f6ba54fac748191ed92ae5ebbcf 100644 (file)
@@ -44,7 +44,7 @@ static int test_unit_file_get_set(void) {
         Iterator i;
         UnitFileList *p;
 
         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);
         assert(h);
 
         r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
index 3bab7ac13786439d4db4f8b6e1ad06673980632d..f9830c431d2b905aa46fae305640930a5a93fd55 100644 (file)
@@ -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. */
 
         /* 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;
 
         if (!unix_sockets)
                 return;
 
@@ -1608,8 +1608,8 @@ int main(int argc, char *argv[]) {
 
         label_init(NULL);
 
 
         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();
 
         if (!items || !globs) {
                 r = log_oom();