Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to use "fnv1" hash function in boost unordered?

Reply
Thread Tools

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

 
 
sschnug
Guest
Posts: n/a
 
      02-02-2009
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\f nv1.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
 
Reply With Quote
 
 
 
 
Michael DOUBEZ
Guest
Posts: n/a
 
      02-03-2009
sschnug wrote:
> 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\f nv1.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

--
Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
pass a boost::function as an argument to boost::bind Christopher C++ 1 10-05-2011 11:35 AM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
Any Boost Experts out there for Boost.Regex? Richard Latter C++ 2 05-17-2004 03:12 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57