Title

安全的哈希

安全的哈希

代码如下

struct custom_hash 
{
	static uint64_t splitmix64(uint64_t x) 
    {
		x ^= x << 13;
		x ^= x >> 7;
		x ^= x << 17;
		return x; 
	}
	size_t operator () (uint64_t x) const 
    {
		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
		return splitmix64(x + FIXED_RANDOM);
	}
};
std::unordered_map<uint64_t, int, custom_hash> mp;
posted @ 2024-10-06 15:28  栗悟饭与龟功気波  阅读(10)  评论(0编辑  收藏  举报