#ifndef _HMAP_H #define _HMAP_H #include "map.h" #include "vector.h" #include "hiterator.h" // implement the map class using an hash table // // Owen Astrachan 11/8/95 // // performance: IncludesKey is O(1) for an n-element map // GetValue also O(1), Insert is O(1) because of find // // template class HMapIterator; template struct Node { Type info; Node * next; }; template class HMap : public Map { public: HMap(unsigned int (*hash) (const Key &),int size); ~HMap(); virtual void Apply(void (*Func) (Pair & p)); // apply Func virtual void Apply(MapBase & obj); // apply obj virtual bool IncludesKey(const Key & key) const; // is key in map? virtual const Value& GetValue(const Key & key) const; // get // value virtual bool IncludesKey(const Key & key, Value & val); virtual Value& GetValue(const Key & key); // get value virtual void GetValue(Pair & pair); // get value virtual void Delete(const Key & key); virtual void Insert(const Key & key, const Value & value); virtual void Insert(const Pair & pair); // add pair to map // (no duplicates) friend class HMapIterator >; virtual Iterator > * MakeIterator(); private: Node >* Find(const Key & key) const; // helper function Vector > *> myList; // vector of nodes int myNumElts; // # elements stored unsigned int (*myFunction)(const Key &); HMap(const HMap & map); // disable copy constructor HMap& operator=(const HMap & map); // disable assignments }; #endif // _HMAP_H undefined