32 lines
		
	
	
		
			597 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			597 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| #include <cstdint>
 | |
| 
 | |
| namespace Chattr {
 | |
| 
 | |
| 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 std {
 | |
| template <>
 | |
| struct hash<Chattr::Snowflake> {
 | |
|     std::size_t operator()(const Chattr::Snowflake& k) const {
 | |
|         return std::hash<uint64_t>{}(k.snowflake);
 | |
|     }
 | |
| };
 | |
| } |