generic Map question

I need help with a generic Map that supports the insert and lookup operations. The implementation will store a hash table of pairs (key, definition). You will lookup a definition by providing a key. This is what I have so far. I don't know what is missing.

template <typename HashedObj, typename Object>
class Pair
{
HashedObj key;
Object def;
// Appropriate Constructors, etc.

};

template <typename HashedObj, typename Object>
class Dictionary
{

public:
Dictionary( );

void insert( const HashedObj & key, const Object & definition );
const Object & lookup( const HashedObj & key ) const;
bool isEmpty( ) const;
void makeEmpty( );

private:
HashTable<Pair<HashedObj,Object> > items;

};
EDIT: Actually...why exactly would you want to "insert" something into a map...it's stored by a key so it doesn't matter where it is...if it is just adding something to it, you can do that with a normal map too...

Actually, you can do both of these with a normal map...
Last edited on
What is the problem?
What's the difference between Dictionary and HashTable? A dictionary stores a relation between a unique key of type T and a value of type T2. A hashmap is a special case of a dictionary in which the keys are hashed before any indexing operation, and the hash is used as the key, instead. Where does Dictionary keep the keys?
Since a hashmap is a special case of a dictionary, it'd make more sense that HashMap had an instance of Dictionary, not viceversa.

Yeah, I agree with firedraco. insert() should be called add(), since you can't tell it where to insert.
Last edited on
Although the sequence STL containers such as set, map, multiset, and multimap all use "insert" instead of "add".

I'd use insert because it conforms to STL.

Topic archived. No new replies allowed.