IDGen¶
This page describes the class LinearBirth
The class IDGen
generates unique IDs typically used fo agentIDs.
For a particular IDGen
object the generated IDs have the form “\(base + offset + k*increment\)”.
This makes it possible to create globally unique IDs even when running on multiple threads.
In such a case we use one IDGen
object per thread where the offset of IDGen[i]
is i
and the increment is equal to the number of threads.
- Code:
Public Methods¶
constructor
¶
IDGen(idtype iBase, idtype iOffs, idtype iIncrement);
iBase
ID base. Usually the highest ID that has been found so far.
iOffs
Offset. Typically the index of the thread or process.
iIncrement
Increment between successive IDs. Typically the number of threads or processses.
The constructor prepares the state for the first ID.
setBase
¶
void setBase(idtype iBase);
iBase
ID base.
Here the actual preparation for the IDs takes place.
setData
¶
void setData(idtype iBase, idtype iOffs, idtype iIncrement);
iBase
ID base.
iOffs
Offset.
iIncrement
Increment between successive IDs.
Updates the values for base offset and increment, then prepares for the first ID.
getID
¶
inline idtype getID();
Returns the next ID.
getCur
¶
idtype getCur();
Returns the last generated ID (the actual internal state, needed for dump & restore).
setCur
¶
void setCur(idtype iCur);
iCur
New state.
Sets the internal state to the new value (needed for dump & restore).