Class l2df.manager.gsid
Global Synchronized Identifier generator.
Its main advantages are simplicity and ability to revert its inner state.
Info:
- Copyright: Atom-TM 2020
- Author: Abelidze
Functions
Manager:init([kwargs]) | Configure GSID manager. |
Manager:advance(dt) | Advances inner counter used for generation of GSIDs. |
Manager:generate() | Generates next GSID hash value from the inner state. |
Manager:hash(state, salt) | Generates new GSID hash value using specified state and salt . |
Manager:rand() | Generates random GSID. |
Functions
Methods- Manager:init([kwargs])
-
Configure GSID manager.
Parameters:
-
kwargs
table
-
seed
number
Generator needs a number to start with (a
seed
value), to be able to generate GSID's sequences. (default 1) - step number Generator's fixed step value for updating the inner state by calling GSID:advance() method. (default 1)
-
salt
number
Additional salt used in hash generation. Can be used to generate different
GSID's sequences for the same initial
seed
. (default 1)
-
seed
number
Generator needs a number to start with (a
Returns:
-
kwargs
table
- Manager:advance(dt)
-
Advances inner counter used for generation of GSIDs.
Note that it doesn't affect generator's state immediately because it updates with the fixed step.
So the specified delta will be accumulated and applied to the state as soon as it achieves the step value.
Parameters:
- dt number Delta value to advance the inner generator's counter. Could be a positive or negative number.
- Manager:generate()
-
Generates next GSID hash value from the inner state.
Returns:
-
string
HEX representation of the generated GSID.
- Manager:hash(state, salt)
-
Generates new GSID hash value using specified
state
andsalt
.Parameters:
-
state
number
Source state value. Must be greater than
zero
. -
salt
number
Additional salt value. Must be greater than
zero
.
Returns:
-
string
HEX representation of the generated GSID.
-
state
number
Source state value. Must be greater than
- Manager:rand()
-
Generates random GSID.
Returns:
-
number
Number representation of the generated GSID.