Pages

Tuesday, March 22, 2011

Hash Map class for stdext

Here’s a hash map derived class that works

typedef vector<char> Key;
typedef list<vector<char> > Element;
class my_hash_compare: public stdext::hash_compare<Key>{
public:
    bool operator( )( const Key& _Key1,const Key& _Key2 ) const
    {
        // add your own logic to compare _Key1 and _Key2
        return true; // return the result of compare
    }
};
//template<class T, class S>
class Mymap: public stdext::hash_map <Key, Element, my_hash_compare>
{
};

or
Code Block
typedef vector<char> Key;
typedef list<vector<char> > Element;
struct myLess: public less<Key>
{
    bool operator()(const Key& _Left, const Key& _Right) const
    {
        //your own logic to compare _Left and _Right
        return true; // return the result of compare
    }
};
//template<class T, class S>
class Mymap: public stdext::hash_map <Key, Element, hash_compare<Key,myLess> >
{
};

No comments:

Post a Comment