tcp/udp 추가, todo:iocp openssl 지원하도록 업데이트하기
This commit is contained in:
32
include/utils/snowflake.h
Normal file
32
include/utils/snowflake.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct Snowflake {
|
||||
union {
|
||||
struct {
|
||||
std::uint64_t timestamp : 42;
|
||||
std::uint64_t instance : 10;
|
||||
std::uint64_t sequence : 12;
|
||||
};
|
||||
std::uint64_t snowflake;
|
||||
};
|
||||
|
||||
bool operator==(const Snowflake& other) const {
|
||||
return snowflake == other.snowflake;
|
||||
}
|
||||
};
|
||||
|
||||
Snowflake GenerateID();
|
||||
|
||||
} // namespace Chattr
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<utils::Snowflake> {
|
||||
std::size_t operator()(const utils::Snowflake& k) const {
|
||||
return std::hash<std::uint64_t>{}(k.snowflake);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
Reference in New Issue
Block a user