468,469 Members | 1,962 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

hash function for std::vector<int> needed

Hi,

I'd like to hash std::vector<intobjects using hash_set, but I'm not
sure what hash function to use. Does anybody have a suggestion?

Thank you!
Markus
Nov 18 '07 #1
2 8096
On Nov 18, 10:23 am, Markus Dehmann <markus.dehm...@gmail.comwrote:
Hi,

I'd like to hash std::vector<intobjects using hash_set, but I'm not
sure what hash function to use. Does anybody have a suggestion?

Thank you!
Markus
Possibly you can use boost::hash_combine<intacross the vector
(warning, unchecked):
std::size_t vectorhash(std::vector<intf){
size_t seed = 0;
for_each(f.start(), f.end(), boost::bind(hash_combine<int>, seed,
_1));
return seed;
}
Nov 18 '07 #2
On Nov 17, 9:47 pm, alan <almkg...@gmail.comwrote:
On Nov 18, 10:23 am, Markus Dehmann <markus.dehm...@gmail.comwrote:
Hi,
I'd like to hash std::vector<intobjects using hash_set, but I'm not
sure what hash function to use. Does anybody have a suggestion?
Thank you!
Markus

Possibly you can use boost::hash_combine<intacross the vector
(warning, unchecked):
std::size_t vectorhash(std::vector<intf){
size_t seed = 0;
for_each(f.start(), f.end(), boost::bind(hash_combine<int>, seed,
_1));
return seed;

}
Perfect! Apparently it gets even easier. After reading this I googled
for hash_combine and found hash_range:

std::vector<std::stringsome_strings;
std::size_t hash = boost::hash_range(some_strings.begin(),
some_strings.end());

(http://www.boost.org/doc/html/hash/combine.html)

M.

Nov 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ingo Nolden | last post: by
3 posts views Thread by Rakesh Sinha | last post: by
6 posts views Thread by Roman Töngi | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.