text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

HashMap.cpp

Go to the documentation of this file.
00001 
00017 template <typename Key, typename T, typename Hash>
00018 HashMap<Key, T, Hash>::HashMap(int maxBuckets)
00019 {
00020    hash = Hash();
00021    resize(maxBuckets + 1);
00022 }  // end constructor
00023 
00024 template <typename Key, typename T, typename Hash>
00025 T& HashMap<Key, T, Hash>::operator[](Key& key)
00026 {
00027    return at(hash(key))[key];
00028 }  // end operator[]
00029 
00030 template <typename Key, typename T, typename Hash>
00031 map<Key, T>::const_iterator HashMap<Key, T, Hash>::findItem(const Key& key)
00032 {
00033    map<Key, T>::const_iterator it;
00034    int index = hash(key);
00035    it = at(index).find(key);
00036 
00037    return it;
00038 } // end findItem
00039 
00040 template <typename Key, typename T, typename Hash>
00041 void HashMap<Key, T, Hash>::insert(const Key& key,
00042                                     const T& item)
00043 {
00044    int index = hash(key);
00045    at(index).insert(make_pair(key, item));
00046 }  // end insert
00047 
00048 template <typename Key, typename T, typename Hash>
00049 int HashMap<Key, T, Hash>::erase(const Key& key)
00050 {
00051    int index = hash(key);
00052    return at(index).erase(key);
00053 }  // end erase
00054 // End of implementation file

Generated on Sun Aug 27 22:18:13 2006 for AWLogo by  doxygen 1.4.6