473,381 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

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 9070
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ingo Nolden | last post by:
Hi, I am using spirit 1.31 I have been trying the following example from the spirit docs. I tried it with int and double neither works: vector<int> v; rule<> r = list_p(int_p, ch_p(',')); ...
3
by: Rakesh Sinha | last post by:
This is about the vector template defined in standard C++ . Suppose I want to create a *huge* vector , as follows. void f1() { vector < int > data(1024); //may be not very huge, but for...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
6
by: Roman Töngi | last post by:
I want to change a vector in a function. I pass a pointer of it to the function and append an item. Then I want to print the first item in the vector. It doesn't work. Can anyone help me? Thanks...
10
by: arnuld | last post by:
WANTED: /* C++ Primer - 4/e * * Exercise: 9.26 * STATEMENT * Using the following definition of ia, copy ia into a vector and into a list. Use the single iterator form of erase to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.