#pragma once #include "utils.hpp" #include #include #include namespace odhtdb { const int HASH_BYTE_SIZE = 32; // Source: https://stackoverflow.com/a/11414104 (public license) static size_t fnvHash(const unsigned char *key, int len) { size_t h = 2166136261; for (int i = 0; i < len; i++) h = (h * 16777619) ^ key[i]; return h; } class HashException : public std::runtime_error { public: HashException(const std::string &errMsg) : std::runtime_error(errMsg) {} }; // Uses blake2b to hash input class Hash { public: Hash(); // Throws HashException on failure Hash(const void *input, const size_t inputSize); Hash(const Hash &other); void* getData() const { return (void*)data; } size_t getSize() const { return HASH_BYTE_SIZE; } size_t operator()() const; bool operator==(const Hash &other) const; bool operator!=(const Hash &other) const; bool isEmpty() const; std::string toString() const; private: char data[HASH_BYTE_SIZE]; }; struct HashHasher { size_t operator()(const Hash &hash) const { return hash(); } }; template using MapHash = std::unordered_map; using SetHash = std::unordered_set; }