aboutsummaryrefslogtreecommitdiff
path: root/src/core/idhash.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2023-12-29 17:43:50 -0800
committerGarrett D'Amore <garrett@damore.org>2023-12-29 18:25:04 -0800
commit3298ac1e93742e7a1ef5c4dc2e9b603dfa89d3cb (patch)
treea1051ba1a3edcd5bc6c75c9a1f43ae1a14813b45 /src/core/idhash.h
parent5954332f1690e95c329b991a25b2d89b9a44ef02 (diff)
downloadnng-3298ac1e93742e7a1ef5c4dc2e9b603dfa89d3cb.tar.gz
nng-3298ac1e93742e7a1ef5c4dc2e9b603dfa89d3cb.tar.bz2
nng-3298ac1e93742e7a1ef5c4dc2e9b603dfa89d3cb.zip
fixes #1740 Public ID hash API
This includes a manual page documenting the entire set of functions in one step. The hash is 64-bit based for now, to be maximally flexible. An internal 32-bit convenience for the common internal use is also provided (not public). The public API includes a test suite.
Diffstat (limited to 'src/core/idhash.h')
-rw-r--r--src/core/idhash.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/core/idhash.h b/src/core/idhash.h
index e8894dfb..b2c07062 100644
--- a/src/core/idhash.h
+++ b/src/core/idhash.h
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2023 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
@@ -28,16 +28,17 @@ typedef struct nni_id_entry nni_id_entry;
// NB: These details are entirely private to the hash implementation.
// They are provided here to facilitate inlining in structures.
+// We can support at most 2^32 ~ 4 billion ~ entries.
struct nni_id_map {
+ uint32_t id_flags;
uint32_t id_cap;
uint32_t id_count;
uint32_t id_load;
uint32_t id_min_load; // considers placeholders
uint32_t id_max_load;
- uint32_t id_min_val;
- uint32_t id_max_val;
- uint32_t id_dyn_val;
- uint32_t id_flags;
+ uint64_t id_min_val;
+ uint64_t id_max_val;
+ uint64_t id_dyn_val;
nni_id_entry *id_entries;
};
@@ -45,12 +46,13 @@ struct nni_id_map {
#define NNI_ID_FLAG_RANDOM 2 // start at a random value
#define NNI_ID_FLAG_REGISTER 4 // map is registered for finalization
-extern void nni_id_map_init(nni_id_map *, uint32_t, uint32_t, bool);
+extern void nni_id_map_init(nni_id_map *, uint64_t, uint64_t, bool);
extern void nni_id_map_fini(nni_id_map *);
-extern void *nni_id_get(nni_id_map *, uint32_t);
-extern int nni_id_set(nni_id_map *, uint32_t, void *);
-extern int nni_id_alloc(nni_id_map *, uint32_t *, void *);
-extern int nni_id_remove(nni_id_map *, uint32_t);
+extern void *nni_id_get(nni_id_map *, uint64_t);
+extern int nni_id_set(nni_id_map *, uint64_t, void *);
+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);
#define NNI_ID_MAP_INITIALIZER(min, max, flags) \