#include <iostream> #include <cstring> #include <map> #include <unordered_map> #include <vector> using namespace std; template<typename T> class HashEntry { public: int hash; string key; T value; HashEntry<T> * next; HashEntry(){} HashEntry(int hash, string key, T value, HashEntry<T> * e) { this->hash = hash; this->key = key; this->value = value; this->next = e; } int hashCode() { std::hash<string> k; std::hash<T> v; return (int) (k(key) ^ v(value)); } bool equal(void *e) { if(e == this) return true; if(HashEntry<T>* temp = dynamic_cast<HashEntry<T>*>(e)) { if(this->hash == temp->hash && this->key.compare(temp->key) == 0 && this->value == temp->value) { return true; } } return false; } }; template<typename T> class HashMap { private: HashEntry<T> ** table; int size; int capacity; double
C++ 哈希表
最新推荐文章于 2024-05-24 17:20:13 发布