OpenMS
Loading...
Searching...
No Matches
UniqueIdGenerator Class Reference

A generator for unique ids. More...

#include <OpenMS/CONCEPT/UniqueIdGenerator.h>

Static Public Member Functions

static UInt64 getUniqueId ()
 Returns a new, nonzero unique id.
 
static std::string getUUID ()
 Returns a new random UUID (version 4)
 
static void setSeed (UInt64 seed)
 Reseed the shared generator.
 
static UInt64 getSeed ()
 Get the seed.
 

Protected Member Functions

 UniqueIdGenerator ()
 
 ~UniqueIdGenerator ()
 

Private Member Functions

 UniqueIdGenerator (const UniqueIdGenerator &)
 

Detailed Description

A generator for unique ids.

The unique ids are nonzero 64-bit random unsigned integers. All callers share one generator with process lifetime. The random generator is std::mt19937_64 (MT19937-64), whose output sequence is fully specified by the algorithm and therefore identical on every platform and standard library. Zero engine outputs are skipped because they represent an invalid unique id. Random values can still collide; map-level uniqueness must be checked separately.

A mutex guards every draw, so generation is thread-safe with or without OpenMP. The ids are the consecutive outputs of the shared engine, except for skipped zeros: for a given seed, the ids drawn up to any point are the same set however many threads drew them. Only which thread receives which id depends on scheduling.

Constructor & Destructor Documentation

◆ UniqueIdGenerator() [1/2]

UniqueIdGenerator ( )
protected

◆ ~UniqueIdGenerator()

~UniqueIdGenerator ( )
protected

◆ UniqueIdGenerator() [2/2]

UniqueIdGenerator ( const UniqueIdGenerator &  )
private

Member Function Documentation

◆ getSeed()

static UInt64 getSeed ( )
static

Get the seed.

◆ getUniqueId()

static UInt64 getUniqueId ( )
static

Returns a new, nonzero unique id.

◆ getUUID()

static std::string getUUID ( )
static

Returns a new random UUID (version 4)

Formatted as the standard 36-character string "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".

◆ setSeed()

static void setSeed ( UInt64  seed)
static

Reseed the shared generator.

Parameters
[in]seedSeed for the Mersenne Twister engine.