A container for a 64 bit unsigned value representing many things on discord. This value is known in distributed computing as a snowflake value.
More...
#include <snowflake.h>
A container for a 64 bit unsigned value representing many things on discord. This value is known in distributed computing as a snowflake value.
Snowflakes are:
- Performant (very fast to generate at source and to compare in code)
- Uncoordinated (allowing high availability across clusters, data centres etc)
- Time ordered (newer snowflakes have higher IDs)
- Directly Sortable (due to time ordering)
- Compact (64 bit numbers, not 128 bit, or string)
An identical format of snowflake is used by Twitter, Instagram and several other platforms.
- See also
- https://en.wikipedia.org/wiki/Snowflake_ID
-
https://github.com/twitter-archive/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231
◆ snowflake() [1/3]
dpp::snowflake::snowflake |
( |
const uint64_t & |
value | ) |
|
Construct a snowflake object.
- Parameters
-
◆ snowflake() [2/3]
dpp::snowflake::snowflake |
( |
const std::string & |
string_value | ) |
|
Construct a snowflake object.
- Parameters
-
string_value | A snowflake value |
◆ snowflake() [3/3]
dpp::snowflake::snowflake |
( |
| ) |
|
Construct a snowflake object.
◆ ~snowflake()
dpp::snowflake::~snowflake |
( |
| ) |
|
|
default |
Destroy the snowflake object.
◆ empty()
bool dpp::snowflake::empty |
( |
| ) |
const |
|
inline |
Returns true if the snowflake holds an empty value (is 0)
- Returns
- true if empty (zero)
◆ get_creation_time()
double dpp::snowflake::get_creation_time |
( |
| ) |
const |
Get the creation time of this snowflake according to Discord.
- Returns
- double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.
◆ get_increment()
uint16_t dpp::snowflake::get_increment |
( |
| ) |
const |
Get the increment, which is incremented for every snowflake created over the one millisecond resolution in the timestamp.
- Returns
- uint64_t millisecond increment
◆ get_process_id()
uint8_t dpp::snowflake::get_process_id |
( |
| ) |
const |
Get the process id that produced this snowflake value.
- Returns
- uint8_t process id
◆ get_worker_id()
uint8_t dpp::snowflake::get_worker_id |
( |
| ) |
const |
Get the worker id that produced this snowflake value.
- Returns
- uint8_t worker id
◆ operator uint64_t()
dpp::snowflake::operator uint64_t |
( |
| ) |
const |
For acting like an integer.
- Returns
- The snowflake value
◆ operator uint64_t &()
dpp::snowflake::operator uint64_t & |
( |
| ) |
|
For acting like an integer.
- Returns
- A reference to the snowflake value
◆ operator=() [1/2]
snowflake & dpp::snowflake::operator= |
( |
const std::string & |
snowflake_val | ) |
|
Assign from std::string.
- Parameters
-
snowflake_val | string to assign from. |
◆ operator=() [2/2]
snowflake & dpp::snowflake::operator= |
( |
const uint64_t & |
snowflake_val | ) |
|
Assign from std::string.
- Parameters
-
snowflake_val | value to assign from. |
◆ operator==() [1/2]
bool dpp::snowflake::operator== |
( |
const snowflake & |
other | ) |
const |
Check if one snowflake value is equal to another.
- Parameters
-
other | other snowflake to compare |
- Returns
- True if the snowflake objects match
◆ operator==() [2/2]
bool dpp::snowflake::operator== |
( |
const uint64_t & |
other | ) |
const |
Check if one snowflake value is equal to a uint64_t.
- Parameters
-
other | other snowflake to compare |
- Returns
- True if the snowflake objects match
◆ operator<
Operator less than, used for maps/unordered maps when the snowflake is a key value.
- Parameters
-
lhs | fist snowflake to compare |
rhs | second snowflake to compare |
- Returns
- true if lhs is less than rhs
◆ std::hash< dpp::snowflake >
◆ value
uint64_t dpp::snowflake::value |
|
protected |