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

STL hash_set problem, SGI impl

Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and
I've having problem
instantiating a hash_set with a custom hash function, I could really use
some help sifting through g++ (v3.3.3)
error message on this particular problem.

I want a hash_set with class pointers as the hashed type, my class is
simply called Transition, the following code
doesn't work;

using namespace __gnu_cxx;

typedef struct _HashFunc : public unary_function<Transition *, size_t > {
size_t operator()( const Transition *t ) const {
return t->getID();
}
} HashFunc;

void foo( Transition *trans ) {
hash_set< Transition *, hash<HashFunc> > my_hashset; // This far the
compiler doesn't complain...
myhashset.insert( trans ); // however, adding this instatiation causes
the following error;

}

/usr/include/c++/3.3.3/ext/stl_hashtable.h: In member function `size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num_key(const _Key&, unsigned int) const [with _Val =
Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>,
_ExtractKey = std::_Identity<Transition*>, _EqualKey =
std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]':
/usr/include/c++/3.3.3/ext/stl_hashtable.h:519: instantiated from `size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num(const _Val&, unsigned int) const [with _Val =
Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>,
_ExtractKey = std::_Identity<Transition*>, _EqualKey =
std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]'
/usr/include/c++/3.3.3/ext/stl_hashtable.h:884: instantiated from `void
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::resize(unsigned int) [with _Val = Transition*, _Key = Transition*,
_HashFcn = __gnu_cxx::hash<HashFunc>, _ExtractKey =
std::_Identity<Transition*>, _EqualKey = std::equal_to<Transition*>, _Alloc
= std::allocator<Transition*>]'
/usr/include/c++/3.3.3/ext/stl_hashtable.h:378: instantiated from
`std::pair<__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey,
_EqualKey, _Alloc>, bool> __gnu_cxx::hashtable<_Val, _Key, _HashFcn,
_ExtractKey, _EqualKey, _Alloc>::insert_unique(const _Val&) [with _Val =
Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>,
_ExtractKey = std::_Identity<Transition*>, _EqualKey =
std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]'
/usr/include/c++/3.3.3/ext/hash_set:175: instantiated from
`std::pair<typename __gnu_cxx::hashtable<_Value, _Value, _HashFcn,
std::_Identity<_Key>, _EqualKey, _Alloc>::const_iterator, bool>
__gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc>::insert(typename
__gnu_cxx::hashtable<_Value, _Value, _HashFcn, std::_Identity<_Key>,
_EqualKey, _Alloc>::value_type&) [with _Value = Transition*, _HashFcn =
__gnu_cxx::hash<HashFunc>, _EqualKey = std::equal_to<Transition*>, _Alloc =
std::allocator<Transition*>]'
net.cpp:328: instantiated from here
/usr/include/c++/3.3.3/ext/stl_hashtable.h:514: error: no match for call to
`(
const __gnu_cxx::hash<HashFunc>) (Transition* const&)'

Ok, so I've figured out that somewhere deep down in the template we try and
call the HashFunc operator() and we cant find a match,
I just cant fix the HashFunc functor with the correct types for this to
work?

Or am I missing something?

/tq

Jul 22 '05 #1
1 3924
Timo Qvist wrote:
Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and
I've having problem
instantiating a hash_set with a custom hash function, I could really use
some help sifting through g++ (v3.3.3)
error message on this particular problem.

I want a hash_set with class pointers as the hashed type, my class is
simply called Transition, the following code
doesn't work;

using namespace __gnu_cxx;

typedef struct _HashFunc : public unary_function<Transition *, size_t > {
size_t operator()( const Transition *t ) const {
Try changing this to

size_t operator()(Transition * const & t ) const {

return t->getID();
}
} HashFunc;

void foo( Transition *trans ) {
hash_set< Transition *, hash<HashFunc> > my_hashset; // This far the
compiler doesn't complain...
myhashset.insert( trans ); // however, adding this instatiation causes
the following error;

}

[...]
/usr/include/c++/3.3.3/ext/stl_hashtable.h:514: error: no match for call to
`(
const __gnu_cxx::hash<HashFunc>) (Transition* const&)' ^^^^^^^^^^^^^^^^^^
That's the type it expects to find
Ok, so I've figured out that somewhere deep down in the template we try and
call the HashFunc operator() and we cant find a match,
I just cant fix the HashFunc functor with the correct types for this to
work?

Or am I missing something?


I guess so...

V
Jul 22 '05 #2

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

Similar topics

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...
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
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...
2
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects"...
1
by: leslie_tighe | last post by:
Hello, I have webservice created with Axis 1.2.1 and that I am trying to consuming in .NET (VB) using the Microsoft provided tools. While I am able to consume methods on the service that return...
9
by: Cesar | last post by:
Hello there, A java programmer sent me a wsdl file, which I have to use to consume his web methods. When I run the wsld.exe tool to generate the class' code, I get the following message: ...
8
by: Rakesh | last post by:
Hi - What is wrong this implementation? I get a core dump at the free() statement? Thanks Rakesh #include <ext/hash_map> #include <iostream.h> #include <ext/hash_set>
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.