![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
Monotonically increasing ID allocator. More...
#include <dfx-utilities/MonotonicIdAllocator.hpp>
Public Types | |
| using | value_type = T |
| Type used for allocated identifiers. | |
Public Member Functions | |
| value_type | next () noexcept |
| Allocate and return the next identifier. | |
| void | reset () noexcept |
| Reset the allocator counter back to zero. | |
Monotonically increasing ID allocator.
MonotonicIdAllocator hands out numeric identifiers by incrementing an internal counter.
The allocator is intentionally simple:
IDs are guaranteed to be unique for the lifetime of the allocator instance as long as reset() is not called and the counter does not overflow.
| T | Integral type used for identifiers (e.g. uint32_t, uint64_t). |
| using dfx::Utils::MonotonicIdAllocator< T >::value_type = T |
Type used for allocated identifiers.
|
inlinenoexcept |
Allocate and return the next identifier.
Returns the current counter value and increments it afterward (post-increment). The first call returns 0.
|
inlinenoexcept |
Reset the allocator counter back to zero.
After calling reset(), subsequent calls to next() will start again from 0, which can create duplicates relative to IDs previously handed out by this same allocator instance.
Use only when you can guarantee that no previously issued IDs are still in use (or when duplicates are acceptable for your use-case).