📄 hashmap.h
字号:
// *************************************************// Header file HashMap.h // The HashMap is derived from the STL vector and map // *************************************************#include <vector>#include <map>using namespace std;template <class Key, class T, class Hash>class HashMap : private vector<map<Key, T> > { public: HashMap(const int maxBuckets); // Constructor // Precondition: The HashMap is empty. // Postcondition: The HashMap is initialized to hold // maxBuckets. The Hash template parameter is assigned to // the hash variable. T& operator[](Key& key); // Overloads the subscript operator for the HashMap class // Precondition: The HashMap contains a hash for type T. // Postcondition: The value of a hashed key is returned. map<Key, T>::const_iterator findItem(const Key& key); // Hashes the key to find the vector index. // Finds the map element using the key as the index. // Precondition: The HashMap contains a hash for type T. // Postcondition: An iterator to the (key, item) pair is // returned. // If the item is not in the map, the iterator points to // the end of the map. void insert (const Key& key, const T& item); // Hashes the key to find the vector index. // Inserts the (key, item) pair into the map at that index. // Precondition: The HashMap contains a hash for the // type T. // Postcondition: The (key, item) pair is inserted // at the hashed index. int erase(const Key& k); // Removes the item with the Key k in the hash table. // Precondition: The HashMap contains a hash for the // type T. // Postcondition: The (key, item) pair at the hashed index // is removed. // The number of items removed is returned (either 0 or 1). Hash hash; // the hash function object}; // end HashMap#include "HashMap.cpp"// End of header file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -