aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/idhash.c26
-rw-r--r--src/core/idhash.h3
2 files changed, 26 insertions, 3 deletions
diff --git a/src/core/idhash.c b/src/core/idhash.c
index 67ae67ea..306c751f 100644
--- a/src/core/idhash.c
+++ b/src/core/idhash.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -366,4 +366,26 @@ nni_id_alloc32(nni_id_map *m, uint32_t *idp, void *val)
NNI_ASSERT(id < (1ULL << 32));
*idp = (uint32_t) id;
return (rv);
-} \ No newline at end of file
+}
+
+bool
+nni_id_visit(nni_id_map *m, uint64_t *keyp, void **valp, uint32_t *cursor)
+{
+ // cursor is just a cursor into the table
+ uint32_t index = *cursor;
+ while (index < m->id_cap) {
+ if (m->id_entries[index].val != NULL) {
+ if (valp != NULL) {
+ *valp = m->id_entries[index].val;
+ }
+ if (keyp != NULL) {
+ *keyp = m->id_entries[index].key;
+ }
+ *cursor = index + 1;
+ return true;
+ }
+ index++;
+ }
+ *cursor = index;
+ return (false);
+}
diff --git a/src/core/idhash.h b/src/core/idhash.h
index b2c07062..11cc7a08 100644
--- a/src/core/idhash.h
+++ b/src/core/idhash.h
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -54,6 +54,7 @@ extern int nni_id_alloc(nni_id_map *, uint64_t *, void *);
extern int nni_id_alloc32(nni_id_map *, uint32_t *, void *);
extern int nni_id_remove(nni_id_map *, uint64_t);
extern void nni_id_map_sys_fini(void);
+extern bool nni_id_visit(nni_id_map *, uint64_t *, void **, uint32_t *);
#define NNI_ID_MAP_INITIALIZER(min, max, flags) \
{ \