These functions provide support for managing tables of data based on
identifiers, ensuring that identifiers are allocated uniquely and within
specified range limits.
The table stores data pointers (which must not be NULL) at a logical numeric index.
It does so efficiently, even if large gaps exist, and it provides a means to efficiently
allocate a numeric identifier from a pool of unused identifiers.
Identifiers are allocated in increasing order, without reusing old identifiers until the
largest possible identifier is allocated. After wrapping, only identifiers that are no longer
in use will be considered.
No effort to order the availability of identifiers based on when they were freed is made.
An initial table is allocated with nng_id_map_alloc(), which takes the lowest legal identifier in lo,
and the largest legal identifier in hi.
The new table is returned in map_p, and should be used as the map argument to the rest of these functions.
The flags argument is a bit mask of flags for the table.
If NNG_MAP_RANDOM is specified, then the starting point for allocations is randomized, but subsequent allocations will then be monotonically increasing.
This is useful to reduce the odds of different instances of an application using the same identifiers at the same time.
The nng_id_get() function returns the value previously stored with the given identifier.
If no value is currently associated with the identifer, it returns NULL.
The nng_id_set() function sets the value with the associated identifier.
This can be used to replace a previously allocated identifier.
If the identifier was not previously allocated, then it is allocated as part of the call.
This function does not necessarily honor the identifier range limits set for the map when it was allocated.
The nng_id_alloc() function allocates a new identifier from the range for the map, and associates it with
the supplied value.
The nng_id_remove() function removes the identifier and its associated value from the table.
|
|
These functions are limited to storing at most 232 identifiers, even though the identifers may
themselves be larger than 232.
|
|
|
These functions are not thread-safe.
Callers should use a mutex or similar approach when thread-safety is needed.
|