gnu_cxx::hash_map vs stdext::hash_map

Started by
12 comments, last by voguemaster 13 years, 6 months ago
Hello,
template<typename OBJ, class HashKey, class EqKey, class CmpKey>class heap2 {public:  heap2();  ~heap2();	void reset();  void add(OBJ val);  void decreaseKey(OBJ val);  bool isIn(OBJ val);  OBJ remove();	void pop() { remove(); }	OBJ top() { return _elts[0]; }	OBJ find(OBJ val);  bool empty();	unsigned size() { return _elts.size(); }//	void verifyData();private:  std::vector<OBJ> _elts;	void heapifyUp(unsigned int index);  void heapifyDown(unsigned int index);	typedef __gnu_cxx::hash_map<OBJ, unsigned int, HashKey, EqKey > IndexTable;	IndexTable table;};


This code snippet compiles just fine under Linux.
Pay attention to __gnu_cxx::hash_map

template<typename OBJ, class HashKey, class EqKey, class CmpKey>class heap2 {public:	heap2();	~heap2();	void reset();	void add(OBJ val);	void decreaseKey(OBJ val);	bool isIn(OBJ val);	OBJ remove();	void pop()	{ remove(); }	OBJ top() { return _elts[0]; }	OBJ find(OBJ val);	bool empty();	unsigned size()	{ return _elts.size(); }private:	std::vector<OBJ> _elts;	void heapifyUp(unsigned int index);	void heapifyDown(unsigned int index);	typedef stdext::hash_map<OBJ, unsigned int, HashKey, EqKey> IndexTable;	IndexTable table;};


while this code snippet has trouble when being instantiated.

	class SearchNode	{	public:		SearchNode(double _fCost=0, double _gCost=0, uint32_t curr=0, uint32_t prev=0)			: fCost(_fCost), gCost(_gCost), currNode(curr), prevNode(prev) { }		SearchNode(uint32_t curr)			: fCost(0), gCost(0), currNode(curr), prevNode(0) { }		double fCost;		double gCost;		uint32_t currNode;		uint32_t prevNode;	};	struct SearchNodeEqual {		bool operator()(const SearchNode& i1, const SearchNode &i2)		{ return i1.currNode == i2.currNode; } };	struct SearchNodeCompare {		bool operator()(const SearchNode &i1, const SearchNode &i2)		{			if (fequal(i1.fCost, i2.fCost))			{				return (fless(i1.gCost, i2.gCost));			}			return (fgreater(i1.fCost, i2.fCost));		} };	struct SearchNodeHash {		size_t operator()(const SearchNode& x) const		{	return (size_t)(x.currNode); }	};	typedef heap2<GenericAStarUtil::SearchNode, GenericAStarUtil::SearchNodeHash,		GenericAStarUtil::SearchNodeEqual, GenericAStarUtil::SearchNodeCompare> PQueue;


GenericAStarUtil::PQueue openQueue;


Error:
1>Compiling...1>GenericAStar.cpp1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(32) : error C2903: 'rebind' : symbol is neither a class template nor a function template1>        d:\program files (x86)\microsoft visual studio 9.0\vc\include\xhash(191) : see reference to class template instantiation 'stdext::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled1>        with1>        [1>            _Kty=GenericAStarUtil::SearchNode,1>            _Ty=unsigned int,1>            _Tr=GenericAStarUtil::SearchNodeHash,1>            _Alloc=GenericAStarUtil::SearchNodeEqual,1>            _Mfl=false1>        ]1>        d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(88) : see reference to class template instantiation 'stdext::_Hash<_Traits>' being compiled1>        with1>        [1>            _Traits=stdext::_Hmap_traits<GenericAStarUtil::SearchNode,unsigned int,GenericAStarUtil::SearchNodeHash,GenericAStarUtil::SearchNodeEqual,false>1>        ]1>        c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\heap2.h(29) : see reference to class template instantiation 'stdext::hash_map<_Kty,_Ty,_Tr,_Alloc>' being compiled1>        with1>        [1>            _Kty=GenericAStarUtil::SearchNode,1>            _Ty=unsigned int,1>            _Tr=GenericAStarUtil::SearchNodeHash,1>            _Alloc=GenericAStarUtil::SearchNodeEqual1>        ]1>        c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\genericastar.h(88) : see reference to class template instantiation 'heap2<OBJ,HashKey,EqKey,CmpKey>' being compiled1>        with1>        [1>            OBJ=GenericAStarUtil::SearchNode,1>            HashKey=GenericAStarUtil::SearchNodeHash,1>            EqKey=GenericAStarUtil::SearchNodeEqual,1>            CmpKey=GenericAStarUtil::SearchNodeCompare1>        ]1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(32) : error C2039: 'rebind' : is not a member of 'GenericAStarUtil::SearchNodeEqual'1>        c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\genericastar.h(27) : see declaration of 'GenericAStarUtil::SearchNodeEqual'

I understand that the declaration differs, but how come the Linux version compiles while the Windows version won't.
Anyone give that a fix, please?

Advertisement
Given
Quote:'rebind' : is not a member of 'GenericAStarUtil::SearchNodeEqual'


and

Quote:d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(32)


have you already looked into that file?


Well, after looking into the documentation I realise you are putting SearchNodeEqual as the fourth parameter to hash_map, but the fourth parameter shall be an allocator.

My guess is you have mistaken the arguments (or maybe the template argument list from gnu differs from ms') ;)
Link

Could anyone lend me hand to make an educated guess what the heck is TP?
:/
Thanks
Jack
Quote:Could anyone lend me hand to make an educated guess what the heck is TP?

My motivation to help you has largely increased ever since you decided to amply bypass my previous reply.
Quote:Original post by phresnel
Quote:Could anyone lend me hand to make an educated guess what the heck is TP?

After you've ignored my previous post, I lost interest.


I haven't. I just tried to map the 2 containers, maybe provide some code snippet?
I just know the "quote" button :)
Quote:Original post by lucky6969b
Quote:Original post by phresnel
Quote:Could anyone lend me hand to make an educated guess what the heck is TP?

After you've ignored my previous post, I lost interest.


I haven't. I just tried to map the 2 containers, maybe provide some code snippet?


Maybe you would just reread my previous reply and try to understand what I've written:

Quote:[...] but the fourth parameter shall be an allocator.


You could try with the default template parameters of MS' implementation and see if it works.

Anyways, never mind.
heap2<HashKey, OBJ, CmpKey>

Should compile, but where is that missing EqKey
MS implmentation has 4 parameters while GNU has 5.
Is it possible to include an equalkey?
Sorry if I have overlooked....
Thanks
Jack
1>Compiling...1>GenericAStar.cpp1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\xhash(199) : error C2039: 'bucket_size' : is not a member of 'GenericAStarUtil::SearchNodeEqual'1>        c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\genericastar.h(27) : see declaration of 'GenericAStarUtil::SearchNodeEqual'1>        d:\program files (x86)\microsoft visual studio 9.0\vc\include\hash_map(88) : see reference to class template instantiation 'stdext::_Hash<_Traits>' being compiled1>        with1>        [1>            _Traits=stdext::_Hmap_traits<GenericAStarUtil::SearchNodeHash,GenericAStarUtil::SearchNode,GenericAStarUtil::SearchNodeEqual,std::allocator<std::pair<const GenericAStarUtil::SearchNodeHash,GenericAStarUtil::SearchNode>>,false>1>        ]1>        c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\heap2.h(29) : see reference to class template instantiation 'stdext::hash_map<_Kty,_Ty,_Tr>' being compiled1>        with1>        [1>            _Kty=GenericAStarUtil::SearchNodeHash,1>            _Ty=GenericAStarUtil::SearchNode,1>            _Tr=GenericAStarUtil::SearchNodeEqual1>        ]1>        c:\users\garfield\documents\visual studio 2008\projects\mock pathfinding\mock pathfinding\util\genericastar.h(89) : see reference to class template instantiation 'heap2<OBJ,HashKey,EqKey,CmpKey>' being compiled1>        with1>        [1>            OBJ=GenericAStarUtil::SearchNode,1>            HashKey=GenericAStarUtil::SearchNodeHash,1>            EqKey=GenericAStarUtil::SearchNodeEqual,1>            CmpKey=GenericAStarUtil::SearchNodeCompare1>        ]


Whoops..still having problems...
Further hints or reading recommendations?
Thanks
Jack
The declaration of MS' hash_map looks like this:

template <   class Key,    class Type,    class Traits=hash_compare<Key, less<Key> >,    class Allocator=allocator<pair <const Key, Type> > >class hash_map



The ='s mean you can omit those last two parameters, in which case the compiler would use what is behind =. So, have you already tried

has_map<YourKey, YourType> foobar;


, just to get it working for a moment?

This topic is closed to new replies.

Advertisement