473,385 Members | 1,373 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,385 software developers and data experts.

Tutorial and example to SGI STL hash_set

Generally, is there somewhere a good tutorial and examplefor the use of
SGI STL hash_set?
I am lost in SGI documentation.

More specifically, i am trying to use hat I need that a hash_set :

hash_set<ch;

and logically the h function for my c class is missing and I get a
compile error.

How do I declare this hash function?
Dec 28 '06 #1
2 7595
Pierre Couderc wrote:
Generally, is there somewhere a good tutorial and examplefor the use of
SGI STL hash_set?
I don't know, but you can get a tutorial for the very similar and
nearly standardized std::tr1::unordered_set in Pete Becker's book on
TR1.
I am lost in SGI documentation.

More specifically, i am trying to use hat I need that a hash_set :

hash_set<ch;

and logically the h function for my c class is missing and I get a
compile error.

How do I declare this hash function?
You need to specialize the hash functor for your class:

#include <hash_set>

class C { /*...*/ };

// Hashable classes must have an == operator
// We'll just stub it out here, pending definition of C
bool operator==( const C&, const C& ) { return true; }

namespace std
{
template<struct hash<C>
{
// Define the hash function. We'll just stub it out here.
size_t operator()( const C& ) const { return 0; }
};
}

void hash_set_test()
{
C c;
std::hash_set<Chsc;
hsc.insert( c );
}

Cheers! --M

Dec 28 '06 #2

Thank you,
It is exactly the example that was missing me. I am sure that it will
be useful tou those who will be looking for "hash-set tutorial"...
The exact syntax of the hash function in not evident for me, even it it
should...
Thank you again,
Pierre

On Dec 28, 4:26 pm, "mlimber" <mlim...@gmail.comwrote:
Pierre Couderc wrote:
Generally, is there somewhere a good tutorial and examplefor the use of
SGI STL hash_set?I don't know, but you can get a tutorial for the very similar and
nearly standardized std::tr1::unordered_set in Pete Becker's book on
TR1.
I am lost in SGI documentation.
More specifically, i am trying to use hat I need that a hash_set :
hash_set<ch;
and logically the h function for my c class is missing and I get a
compile error.
How do I declare this hash function?You need to specialize the hash functor for your class:

#include <hash_set>

class C { /*...*/ };

// Hashable classes must have an == operator
// We'll just stub it out here, pending definition of C
bool operator==( const C&, const C& ) { return true; }

namespace std
{
template<struct hash<C>
{
// Define the hash function. We'll just stub it out here.
size_t operator()( const C& ) const { return 0; }
};
}

void hash_set_test()
{
C c;
std::hash_set<Chsc;
hsc.insert( c );
}

Cheers! --M
Dec 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
0
by: Guennadi V. Vanine | last post by:
I followed IIS ASP Tutorial examples on isolated from net Windows XP Professional available at http://localhost/iishelp/iis/htm/asp/AspTut02.htm In order to run DisplayAds.asp the example on...
1
by: Abhijit Ray | last post by:
I am using hash_set which is available from gcc ( and which i presume is not part of the C++ standard yet ) okay , In hash tables the key is used by a hash function to calculate a index and the...
5
by: Bart Blommerde | last post by:
Hi, My question is about the STL extensions hash_set and hash_map, especially the SGI versions of these templates. When defining a class like this : #include <hash_set> class MyClass : public...
3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
0
by: jtbaccarat | last post by:
The sample Hello World app found in .NET Framework SDK\Tutorials\Hello World, will not compile a .exe file. The build.bat file source code is: @ REM Set command switch for building debug or...
4
by: yuyang08 | last post by:
Hello, everyone, I am wondering what is the hash function that is used in hash_map/hash_set. Can I replace it with my own hash function? Any comments on this? Thanks! -Andy
31
by: Antoon Pardon | last post by:
The following is part of the explanation on slices in the tutorial: The best way to remember how slices work is to think of the indices as pointing between characters, with the left edge of the...
5
by: Markus Dehmann | last post by:
Do I have to handle hash collisions in a hash_set myself? I did a test in which I use find() to look for objects in a hash_set. These objects are definitely not contained, but find() sometimes...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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.