if (n <= 0)
return n;
- h = hashmap_new(string_hash_func, string_compare_func);
+ h = hashmap_new(&string_hash_ops);
if (!h)
return -ENOMEM;
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();
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)
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;
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));
} 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;
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 (r < 0)
return r;
- h = hashmap_new(string_hash_func, string_compare_func);
+ h = hashmap_new(&string_hash_ops);
if (!h)
return -ENOMEM;
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;
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;
return 0;
}
- set = set_new(NULL, NULL);
+ set = set_new(NULL);
if (!set)
return -ENOMEM;
_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);
}
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();
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 (!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();
}
}
- r = set_ensure_allocated(&status_set->status, NULL, NULL);
+ r = set_ensure_allocated(&status_set->status, NULL);
if (r < 0)
return log_oom();
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 (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->units, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->units, &string_hash_ops);
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->jobs, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&m->jobs, NULL);
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->cgroup_unit, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->cgroup_unit, &string_hash_ops);
if (r < 0)
goto fail;
- r = hashmap_ensure_allocated(&m->watch_bus, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->watch_bus, &string_hash_ops);
if (r < 0)
goto fail;
- r = set_ensure_allocated(&m->startup_units, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&m->startup_units, NULL);
if (r < 0)
goto fail;
- r = set_ensure_allocated(&m->failed_units, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&m->failed_units, NULL);
if (r < 0)
goto fail;
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;
return 0;
}
- controllers = set_new(string_hash_func, string_compare_func);
+ controllers = set_new(&string_hash_ops);
if (!controllers)
return log_oom();
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;
return 0;
}
- set = set_new(NULL, NULL);
+ set = set_new(NULL);
if (!set)
return -ENOMEM;
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 (!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;
/* Watch a specific PID. We only support one or two units
* watching each PID for now, not more. */
- r = set_ensure_allocated(&u->pids, trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&u->pids, NULL);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&u->manager->watch_pids1, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&u->manager->watch_pids1, NULL);
if (r < 0)
return r;
r = hashmap_put(u->manager->watch_pids1, LONG_TO_PTR(pid), u);
if (r == -EEXIST) {
- r = hashmap_ensure_allocated(&u->manager->watch_pids2, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&u->manager->watch_pids2, NULL);
if (r < 0)
return r;
return 0;
}
- r = set_ensure_allocated(&u->dependencies[d], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&u->dependencies[d], NULL);
if (r < 0)
return r;
if (inverse_table[d] != _UNIT_DEPENDENCY_INVALID) {
- r = set_ensure_allocated(&other->dependencies[inverse_table[d]], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&other->dependencies[inverse_table[d]], NULL);
if (r < 0)
return r;
}
if (add_reference) {
- r = set_ensure_allocated(&u->dependencies[UNIT_REFERENCES], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&u->dependencies[UNIT_REFERENCES], NULL);
if (r < 0)
return r;
- r = set_ensure_allocated(&other->dependencies[UNIT_REFERENCED_BY], trivial_hash_func, trivial_compare_func);
+ r = set_ensure_allocated(&other->dependencies[UNIT_REFERENCED_BY], NULL);
if (r < 0)
return r;
}
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;
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 (!q)
return -ENOMEM;
- x = set_new(NULL, NULL);
+ x = set_new(NULL);
if (!x) {
free(q);
return -ENOMEM;
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);
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;
**********************************************************************/
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();
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;
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;
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;
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,
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) {
#include "strbuf.h"
int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path);
-unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
-int catalog_compare_func(const void *a, const void *b) _pure_;
int catalog_update(const char* database, const char* root, const char* const* dirs);
int catalog_get(const char* database, sd_id128_t id, char **data);
int catalog_list(FILE *f, const char* database, bool oneline);
int catalog_list_items(FILE *f, const char* database, bool oneline, char **items);
int catalog_file_lang(const char *filename, char **lang);
extern const char * const catalog_file_dirs[];
+extern const struct hash_ops catalog_hash_ops;
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();
char *tmp;
int r;
- set = set_new(trivial_hash_func, trivial_compare_func);
+ set = set_new(NULL);
if (!set) {
log_oom();
return NULL;
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;
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();
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 (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 (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 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 (!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;
}
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;
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"
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;
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;
where->child = c;
if (t == BUS_MATCH_MESSAGE_TYPE) {
- c->compare.children = hashmap_new(trivial_hash_func, trivial_compare_func);
+ c->compare.children = hashmap_new(NULL);
if (!c->compare.children) {
r = -ENOMEM;
goto fail;
}
} else if (BUS_MATCH_CAN_HASH(t)) {
- c->compare.children = hashmap_new(string_hash_func, string_compare_func);
+ c->compare.children = hashmap_new(&string_hash_ops);
if (!c->compare.children) {
r = -ENOMEM;
goto fail;
assert(n);
assert(_s);
- s = set_new(string_hash_func, string_compare_func);
+ s = set_new(&string_hash_ops);
if (!s)
return -ENOMEM;
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;
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,
!streq(interface, "org.freedesktop.DBus.Peer") &&
!streq(interface, "org.freedesktop.DBus.ObjectManager"), -EINVAL);
- r = hashmap_ensure_allocated(&bus->vtable_methods, vtable_member_hash_func, vtable_member_compare_func);
+ r = hashmap_ensure_allocated(&bus->vtable_methods, &vtable_member_hash_ops);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&bus->vtable_properties, vtable_member_hash_func, vtable_member_compare_func);
+ r = hashmap_ensure_allocated(&bus->vtable_properties, &vtable_member_hash_ops);
if (r < 0)
return r;
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 (!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;
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 (!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;
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;
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;
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;
_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();
assert(udev);
- nodes = set_new(string_hash_func, string_compare_func);
+ nodes = set_new(&string_hash_ops);
if (!nodes)
return -ENOMEM;
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);
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)
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 (r < 0)
return -ENOMEM;
- r = hashmap_ensure_allocated(&manager->links, NULL, NULL);
+ r = hashmap_ensure_allocated(&manager->links, NULL);
if (r < 0)
return r;
return -ENOMEM;
}
- m->netdevs = hashmap_new(string_hash_func, string_compare_func);
+ m->netdevs = hashmap_new(&string_hash_ops);
if (!m->netdevs)
return -ENOMEM;
assert(m->state_file);
/* We add all NTP and DNS server to a set, to filter out duplicates */
- dns = set_new(string_hash_func, string_compare_func);
+ dns = set_new(&string_hash_ops);
if (!dns)
return -ENOMEM;
- ntp = set_new(string_hash_func, string_compare_func);
+ ntp = set_new(&string_hash_ops);
if (!ntp)
return -ENOMEM;
- domains = set_new(string_hash_func, string_compare_func);
+ domains = set_new(&string_hash_ops);
if (!domains)
return -ENOMEM;
LIST_HEAD_INIT(network->static_addresses);
LIST_HEAD_INIT(network->static_routes);
- network->stacked_netdevs = hashmap_new(string_hash_func, string_compare_func);
+ network->stacked_netdevs = hashmap_new(&string_hash_ops);
if (!network->stacked_netdevs)
return log_oom();
- network->addresses_by_section = hashmap_new(NULL, NULL);
+ network->addresses_by_section = hashmap_new(NULL);
if (!network->addresses_by_section)
return log_oom();
- network->routes_by_section = hashmap_new(NULL, NULL);
+ network->routes_by_section = hashmap_new(NULL);
if (!network->routes_by_section)
return log_oom();
assert(m);
assert(ifindex > 0);
- r = hashmap_ensure_allocated(&m->links, NULL, NULL);
+ r = hashmap_ensure_allocated(&m->links, NULL);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&m->links_by_name,
- string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&m->links_by_name, &string_hash_ops);
if (r < 0)
return r;
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;
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 (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;
}
}
+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;
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);
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;
assert(q);
assert(s);
- r = set_ensure_allocated(&q->transactions, NULL, NULL);
+ r = set_ensure_allocated(&q->transactions, NULL);
if (r < 0)
return r;
return r;
}
- r = set_ensure_allocated(&t->queries, NULL, NULL);
+ r = set_ensure_allocated(&t->queries, NULL);
if (r < 0)
goto gc;
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;
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;
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_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);
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;
/* 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;
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;
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)
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
+};
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;
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;
assert(z);
- r = hashmap_ensure_allocated(&z->by_key, dns_resource_key_hash_func, dns_resource_key_compare_func);
+ r = hashmap_ensure_allocated(&z->by_key, &dns_resource_key_hash_ops);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&z->by_name, dns_name_hash_func, dns_name_compare_func);
+ r = hashmap_ensure_allocated(&z->by_name, &dns_name_hash_ops);
if (r < 0)
return r;
return r;
}
- r = set_ensure_allocated(&t->zone_items, NULL, NULL);
+ r = set_ensure_allocated(&t->zone_items, NULL);
if (r < 0)
goto gc;
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;
manager_read_resolv_conf(m);
/* Add the full list to a set, to filter out duplicates */
- dns = set_new(dns_server_hash_func, dns_server_compare_func);
+ dns = set_new(&dns_server_hash_ops);
if (!dns)
return -ENOMEM;
- domains = set_new(dns_name_hash_func, dns_name_compare_func);
+ domains = set_new(&dns_name_hash_ops);
if (!domains)
return -ENOMEM;
* 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;
}
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;
}
assert(cto);
assert(pto);
- s = set_new(trivial_hash_func, trivial_compare_func);
+ s = set_new(NULL);
if (!s)
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;
#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) {
};
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;
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);
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);
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;
b = *(const dev_t*) _b;
return a < b ? -1 : (a > b ? 1 : 0);
}
+
+const struct hash_ops devt_hash_ops = {
+ .hash = devt_hash_func,
+ .compare = devt_compare_func
+};
#endif
static unsigned bucket_hash(Hashmap *h, const void *p) {
- return (unsigned) (h->hash_func(p, h->hash_key) % h->n_buckets);
+ return (unsigned) (h->hash_ops->hash(p, h->hash_key) % h->n_buckets);
}
static void get_hash_key(uint8_t hash_key[HASH_KEY_SIZE], bool reuse_is_ok) {
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;
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;
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);
if (*h)
return 0;
- q = hashmap_new(hash_func, compare_func);
+ q = hashmap_new(hash_ops);
if (!q)
return -ENOMEM;
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;
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)
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;
assert(h);
- copy = hashmap_new(h->hash_func, h->compare_func);
+ copy = hashmap_new(h->hash_ops);
if (!copy)
return NULL;
typedef unsigned long (*hash_func_t)(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
typedef int (*compare_func_t)(const void *a, const void *b);
+struct hash_ops {
+ hash_func_t hash;
+ compare_func_t compare;
+};
+
unsigned long string_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
int string_compare_func(const void *a, const void *b) _pure_;
+extern const struct hash_ops string_hash_ops;
/* This will compare the passed pointers directly, and will not
* dereference them. This is hence not useful for strings or
* suchlike. */
unsigned long trivial_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
int trivial_compare_func(const void *a, const void *b) _const_;
+extern const struct hash_ops trivial_hash_ops;
/* 32bit values we can always just embedd in the pointer itself, but
* in order to support 32bit archs we need store 64bit values
* indirectly, since they don't fit in a pointer. */
unsigned long uint64_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
int uint64_compare_func(const void *a, const void *b) _pure_;
+extern const struct hash_ops uint64_hash_ops;
/* On some archs dev_t is 32bit, and on others 64bit. And sometimes
* it's 64bit on 32bit archs, and sometimes 32bit on 64bit archs. Yuck! */
#if SIZEOF_DEV_T != 8
unsigned long devt_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) _pure_;
int devt_compare_func(const void *a, const void *b) _pure_;
+extern const struct hash_ops devt_hash_ops = {
+ .hash = devt_hash_func,
+ .compare = devt_compare_func
+};
#else
-/* No need to define a second version of this... */
#define devt_hash_func uint64_hash_func
#define devt_compare_func uint64_compare_func
+#define devt_hash_ops uint64_hash_ops
#endif
-Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func);
+Hashmap *hashmap_new(const struct hash_ops *hash_ops);
void hashmap_free(Hashmap *h);
void hashmap_free_free(Hashmap *h);
void hashmap_free_free_free(Hashmap *h);
Hashmap *hashmap_copy(Hashmap *h);
-int hashmap_ensure_allocated(Hashmap **h, hash_func_t hash_func, compare_func_t compare_func);
+int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops);
int hashmap_put(Hashmap *h, const void *key, void *value);
int hashmap_update(Hashmap *h, const void *key, void *value);
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;
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;
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;
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;
_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;
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;
/* 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) {
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) {
typedef struct Set Set;
-Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
+Set *set_new(const struct hash_ops *hash_ops);
void set_free(Set* s);
void set_free_free(Set *s);
Set* set_copy(Set *s);
-int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
+int set_ensure_allocated(Set **s, const struct hash_ops *hash_ops);
int set_put(Set *s, void *value);
int set_consume(Set *s, void *value);
}
}
- pids = hashmap_new(NULL, NULL);
+ pids = hashmap_new(NULL);
if (!pids) {
log_oom();
_exit(EXIT_FAILURE);
path_kill_slashes(cleaned);
- done = set_new(string_hash_func, string_compare_func);
+ done = set_new(&string_hash_ops);
if (!done)
return -ENOMEM;
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;
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;
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;
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;
assert(_unit_infos);
assert(_machines);
- replies = set_new(NULL, NULL);
+ replies = set_new(NULL);
if (!replies)
return log_oom();
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();
return r;
}
- s = set_new(string_hash_func, string_compare_func);
+ s = set_new(&string_hash_ops);
if (!s)
return log_oom();
}
if (!f)
return errno == ENOENT ? 0 : -errno;
- r = hashmap_ensure_allocated(&database_user, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&database_user, &string_hash_ops);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&database_uid, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&database_uid, NULL);
if (r < 0)
return r;
if (!f)
return errno == ENOENT ? 0 : -errno;
- r = hashmap_ensure_allocated(&database_group, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&database_group, &string_hash_ops);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&database_gid, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&database_gid, NULL);
if (r < 0)
return r;
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();
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 (!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 (!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();
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();
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();
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();
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;
} 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;
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;
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);
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);
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);
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 *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");
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");
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);
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);
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);
"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");
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);
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);
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);
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);
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);
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);
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);
#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);
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));
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));
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));
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);
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);
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;
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++) {
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);
/* 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;
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();