summaryrefslogtreecommitdiff
path: root/src/supplemental/util/idhash.c
blob: 4ededa31f1b3a646a0cf9a90a9cb44f0a91fbbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// 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));
}

bool
nng_id_visit(nng_id_map *map, uint64_t *id, void **valp, uint32_t *cursor)
{
	return (nni_id_visit(&map->m, id, valp, cursor));
}