Jump to content
  • Advertisement
Sign in to follow this  
supagu

hash_multimap compile errors

This topic is 4423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

right, i'm exporting large amounts of geometry from a 3d program, now its taking a long time as it has to compare verts to remove duplicate data. So i'm gonna use a hash table to speed things up a bit, bit seems it doesnt want to play so nice. this is what i've got:

now my useage:
hash_multimap<float, Vertex, VertexHashFn, VertexEqualKey> mVertexHash;


struct Vertex
{
	vector<Vector3>		mPoint;
	vector<Vector3>		mNormal;
	vector<Vector3>		mTangent;
	vector<Vector3>		mBinormal;
	vector<Vector2>		mTexCoord;
	vector<Vector4>		mColour;

	unsigned int		mIndex; // index this is used by the hash table
};


struct VertexHashFn
{
	float operator()(const Vertex& v1)
	{
		// do hash here and return a float
	}
};


struct VertexEqualKey
{
	bool operator()(const Vertex& v1, const Vertex& v2) const
	{
		// compare, returns true if the same, false otherwise
	}
};

i think something is wrong with either: VertexHashFn or VertexEqualKey. any ideas?

Share this post


Link to post
Share on other sites
Advertisement
It would be useful to know:
  • What the compile errors are

  • Whos hash_multimap implementation you are using (since hash_multimap is non-standard)

Σnigma

Share this post


Link to post
Share on other sites
vc2005

heres the first few it generates:
<source>
Error 2 error C2903: 'rebind' : symbol is neither a class template nor a function template d:\apps\microsoft visual studio 8\vc\include\hash_map 32



Error 3 error C2039: 'rebind' : is not a member of 'VertexEqualKey' d:\apps\microsoft visual studio 8\vc\include\hash_map 32
Error 4 error C2143: syntax error : missing ';' before '<' d:\apps\microsoft visual studio 8\vc\include\hash_map 32
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\apps\microsoft visual studio 8\vc\include\hash_map 32
Error 6 error C2039: 'other' : is not a member of '`global namespace'' d:\apps\microsoft visual studio 8\vc\include\hash_map 32
Error 7 error C2238: unexpected token(s) preceding ';' d:\apps\microsoft visual studio 8\vc\include\hash_map 33
Error 8 error C2039: 'bucket_size' : is not a member of 'VertexHashFn' d:\apps\microsoft visual studio 8\vc\include\xhash 127
Error 9 error C2065: 'bucket_size' : undeclared identifier d:\apps\microsoft visual studio 8\vc\include\xhash 127

</source>

first error takes me here:

typedef typename _Alloc::template rebind<value_type>::other
allocator_type;

in has_map.h

edit:
the third parameter is definately causing some of the errors, the first 2 params work fine

[Edited by - supagu on May 10, 2006 4:01:58 AM]

Share this post


Link to post
Share on other sites
So you're using Microsoft's hash_multimap implementation? The Microsoft hash_multimap class template has four template parameters: Key, Type, Traits and Allocator, with defaults for the last two. Your error therefore is that you are trying to pass a hashing functor as the traits and a key comparison functor as the allocator, which obviously won't work. Instead you need to combine your hashing functor and key comparison function into a compatible traits class and provide only three template parameters to the hash_multimap, i.e.:
struct Vertex
{
vector<Vector3> mPoint;
vector<Vector3> mNormal;
vector<Vector3> mTangent;
vector<Vector3> mBinormal;
vector<Vector2> mTexCoord;
vector<Vector4> mColour;

unsigned int mIndex; // index this is used by the hash table
};


struct VertexHashFn
{
float operator()(const Vertex& v1) const
{
// do hash here and return a float
}
};


struct VertexEqualKey
{
bool operator()(const Vertex& v1, const Vertex& v2) const
{
// compare, returns true if the same, false otherwise
}
};

struct VertexHashTraits
{
static const size_t bucket_size = 4;
static const size_t min_buckets = 8;
size_t operator()(const Vertex & key) const
{
return hash_func(key);
}
bool operator()(const Vertex & lhs, const Vertex & rhs) const
{
return order_func(lhs, rhs);
}

private:

VertexHashFn hash_func;
VertexEqualKey order_func;

};

hash_multimap<float, Vertex, VertexHashTraits> mVertexHash;

Σnigma

Share this post


Link to post
Share on other sites
Good point. In fact now that you've mentioned that I realise that my corrected code still isn't valid because the OP is providing a hashing functor and equality functor which work on Vertexs, but the hash_multimap needs to hash the key, which is of type float. supagu - are you sure you don't want a hash_multiset instead?

Σnigma

Share this post


Link to post
Share on other sites
i got it working, you dont actually need to provide a hash function, you do that when you insert in to the hash.

as for float hash key, good point, im thinking maybe drop any decimal points then return an int, it seems to be working in some cases the hash with a float, but its hard to know if any have slipped through :-/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!