aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/util/idhash.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-01-06 19:22:56 -0800
committerGarrett D'Amore <garrett@damore.org>2024-01-06 19:36:02 -0800
commitf4908daaaad443834d9f270e7ddc5e2e23d0f7a5 (patch)
treed98f33bda4eff47a6561f6fdebe23b9d3909e178 /src/supplemental/util/idhash.c
parentd7e0072a8ef453d6fd06311f6253ba869977e214 (diff)
downloadnng-f4908daaaad443834d9f270e7ddc5e2e23d0f7a5.tar.gz
nng-f4908daaaad443834d9f270e7ddc5e2e23d0f7a5.tar.bz2
nng-f4908daaaad443834d9f270e7ddc5e2e23d0f7a5.zip
fix idhash not public
We accidentally made idhash not public by not publishing its header in the right place. This is really generic utility stuff, so we have posted it in the nng/supplemental/util/ directory. We've also removed the ability to remove this -- its a very small amount of additional code, as its just a wrapper on top of mandatory functionality.
Diffstat (limited to 'src/supplemental/util/idhash.c')
-rw-r--r--src/supplemental/util/idhash.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/supplemental/util/idhash.c b/src/supplemental/util/idhash.c
new file mode 100644
index 00000000..cf48df3e
--- /dev/null
+++ b/src/supplemental/util/idhash.c
@@ -0,0 +1,62 @@
+//
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
+//
+// This software is supplied under the terms of the MIT License, a
+// copy of which should be located in the distribution where this
+// file was obtained (LICENSE.txt). A copy of the license may also be
+// found online at https://opensource.org/licenses/MIT.
+//
+
+#include <nng/nng.h>
+#include <nng/supplemental/util/idhash.h>
+
+#include "core/nng_impl.h"
+
+struct nng_id_map_s {
+ nni_id_map m;
+};
+
+int
+nng_id_map_alloc(nng_id_map **map, uint64_t lo, uint64_t hi, int flags)
+{
+ nng_id_map *m;
+
+ if ((m = NNI_ALLOC_STRUCT(m)) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ nni_id_map_init(
+ &m->m, lo, hi, (flags & NNG_MAP_RANDOM) ? true : false);
+ *map = m;
+ return (0);
+}
+
+void
+nng_id_map_free(nng_id_map *map)
+{
+ nni_id_map_fini(&map->m);
+ NNI_FREE_STRUCT(map);
+}
+
+void *
+nng_id_get(nng_id_map *map, uint64_t id)
+{
+ return (nni_id_get(&map->m, id));
+}
+
+int
+nng_id_set(nng_id_map *map, uint64_t id, void *val)
+{
+ return (nni_id_set(&map->m, id, val));
+}
+
+int
+nng_id_remove(nng_id_map *map, uint64_t id)
+{
+ return (nni_id_remove(&map->m, id));
+}
+
+int
+nng_id_alloc(nng_id_map *map, uint64_t *id, void *val)
+{
+ return (nni_id_alloc(&map->m, id, val));
+}