By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,292 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

hash function for std::vector<int> needed

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.