How to use "fnv1" hash function in boost unordered?

S

sschnug

Hello,
my program is using much hash-based lookups of int vectors (size 1-3).
I don't know which hash function Boost is using, but i wanted to try
fnv1 (maybe faster, maybe less collisions).

The Boost documentation says:
__________________________
For example, if you wanted to use the FNV-1 hash you could write:

boost::unordered_map<std::string, int, hash::fnv_1>
dictionary;

There is an implementation of FNV-1 in the examples directory.
____________________________________________________

Okay, but after including fnv1.hpp from the examples directory and
using the sytax above, compiler is printing out the error:

3-Hitting-Set.cpp:80: error: reference to 'hash' is ambiguous
C:\Program Files\boost\boost_1_36_0\libs\unordered\examples\fnv1.hpp:
13: error:
candidates are: namespace hash { }
c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.3.2/../../../../include/
boost/funct
ional/hash_fwd.hpp:23: error: template<class T> struct
boost::ha
sh
3-Hitting-Set.cpp:80: error: template argument 2 is invalid
3-Hitting-Set.cpp:80: error: invalid type in declaration before ';'
token
3-Hitting-Set.cpp:95: error: request for member 'insert' in 'edges',
which is of
non-class type 'int'

Renaming namespace doesn't work either.

Any ideas?

Thank you very much.

Greetings
Sascha
 
M

Michael DOUBEZ

sschnug said:
Hello,
my program is using much hash-based lookups of int vectors (size 1-3).
I don't know which hash function Boost is using, but i wanted to try
fnv1 (maybe faster, maybe less collisions).

The Boost documentation says:
__________________________
For example, if you wanted to use the FNV-1 hash you could write:

boost::unordered_map<std::string, int, hash::fnv_1>
dictionary;

There is an implementation of FNV-1 in the examples directory.
____________________________________________________

Okay, but after including fnv1.hpp from the examples directory and
using the sytax above, compiler is printing out the error:

3-Hitting-Set.cpp:80: error: reference to 'hash' is ambiguous
C:\Program Files\boost\boost_1_36_0\libs\unordered\examples\fnv1.hpp:
13: error:
candidates are: namespace hash { }
c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.3.2/../../../../include/
boost/funct
ional/hash_fwd.hpp:23: error: template<class T> struct
boost::ha
sh
3-Hitting-Set.cpp:80: error: template argument 2 is invalid
3-Hitting-Set.cpp:80: error: invalid type in declaration before ';'
token
3-Hitting-Set.cpp:95: error: request for member 'insert' in 'edges',
which is of
non-class type 'int'

Renaming namespace doesn't work either.

Any ideas?

Yes: reading the output of your compiler.

There is an ambiguity between namespace hash from fnv1.hpp in the
examples directory and the forward declaration of template<class
T>struct boost::hash;.

There are many solutions:
1. rename namespace hash before using namespace boost
2. don't "using namespace boost"
3. use ::hash::fnv1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top