#pragma once #include #include namespace odhtdb { class Key { public: Key() {} Key(const char *key) : hashedKey(dht::InfoHash::get(key)) {} dht::InfoHash hashedKey; }; // Source: https://stackoverflow.com/a/11414104 (public license) static unsigned int fnvHash(const unsigned char *key, int len) { unsigned int h = 2166136261; for (int i = 0; i < len; i++) h = (h * 16777619) ^ key[i]; return h; } struct KeyHash { size_t operator()(const Key &key) const { return fnvHash(key.hashedKey.data(), key.hashedKey.size()); } }; struct KeyCompare { bool operator()(const Key &lhs, const Key &rhs) const { return lhs.hashedKey == rhs.hashedKey; } }; template using KeyMap = std::unordered_map; }