Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STL hash_set problem, SGI impl

Reply
Thread Tools

STL hash_set problem, SGI impl

 
 
Timo Qvist
Guest
Posts: n/a
 
      11-18-2004
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:air<__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:air<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



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-18-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash_set was not declared even I #include<hash_set> eric C++ 3 07-12-2011 10:27 AM
Tutorial and example to SGI STL hash_set Pierre Couderc C++ 2 12-30-2006 09:12 AM
newbie Q: how to use stl hash_set in gcc3.4.4 zl2k C++ 2 05-14-2006 07:30 PM
SGI STL Chaman Singh C++ 1 04-12-2004 11:11 PM
STL map impl. in C Swamy Muddu C Programming 2 07-23-2003 04:44 PM



Advertisments