Good thinking, David. That solved the
problem, thanks a lot.
Cheers, Oliver Am 14.09.2012 18:15, schrieb Weese, David: Hi, I think the operator mustn't mutate the hash functor, i.e. change size_t operator() (const CharString &key) { into: size_t operator() (const CharString &key) const { Regards, David -- David Weese weese@inf.fu-berlin.de<mailto:weese@inf.fu-berlin.de> Freie Universität Berlin http://www.inf.fu-berlin.de/ Institut für Informatik Phone: +49 30 838 75137 Takustraße 9 Algorithmic Bioinformatics 14195 Berlin Room 020 Am 14.09.2012 um 17:31 schrieb Oliver Stolpe <oliver.stolpe@fu-berlin.de<mailto:oliver.stolpe@fu-berlin.de>>: Hello, I tried to build something like in the example from Wikipedia: struct hashCharString { size_t operator() (const CharString &key) { Iterator<CharString>::Type CharIt; size_t h_value = 7; for (CharIt = begin(key); CharIt != end(key); goNext(CharIt)) { h_value ^= hash<char>()(value(CharIt)); } return h_value; } }; The call is: unordered_map<CharString, unsigned int, hashCharString> kmer; But it fails: /usr/include/c++/4.6/bits/hashtable_policy.h:753:25: Fehler: keine Übereinstimmung für Aufruf von »(const hashCharString) (const seqan::String<char, seqan::Alloc<> >&)« I'm a bit lost here. Oliver Am 14.09.2012 07:29, schrieb Holtgrewe, Manuel: Hi Oliver, does one of these solutions work? http://en.wikipedia.org/wiki/Unordered_associative_containers_(C%2B%2B)#Custom_hash_functions *m ________________________________________ From: Oliver Stolpe [oliver.stolpe@fu-berlin.de] Sent: Thursday, September 13, 2012 11:21 AM To: seqan-dev@lists.fu-berlin.de Subject: [Seqan-dev] CharString as a key in an unordered_map Hello list, I try to use a SeqAn CharString as a key in an unordered_map (C++11). It fails when he tries to link. The linker message is posted below. I think the CharString type is not hashable, therefore I probably need to provide my own hash function (see below). Am I heading in the right direction? Before I start doing this I wanted to know why a string is hashable by the default function but not a CharString? Is there a trick to easily get around this? Thanks, Oliver This is my map structure: unordered_map<CharString, unsigned int> I assume I have to do something like this to provide a hash function (found at stackoverflow): template<> struct hash<typename CharString> { size_t operator() (CharString const &key) { // calculate hash value } }; Linker message: Linking CXX executable fastq_reader CMakeFiles/fastq_reader.dir/fastq_reader.cpp.o: In function `std::_Hashtable<seqan::String<char, seqan::Alloc<void> >, std::pair<seqan::String<char, seqan::Alloc<void> > const, unsigned int>, std::allocator<std::pair<seqan::String<char, seqan::Alloc<void> > const, unsigned int> >, std::_Select1st<std::pair<seqan::String<char, seqan::Alloc<void> > const, unsigned int> >, std::equal_to<seqan::String<char, seqan::Alloc<void> > >, std::hash<seqan::String<char, seqan::Alloc<void> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true>::find(seqan::String<char, seqan::Alloc<void> > const&)': fastq_reader.cpp:(.text._ZNSt10_HashtableIN5seqan6StringIcNS0_5AllocIvEEEESt4pairIKS4_jESaIS7_ESt10_Select1stIS7_ESt8equal_toIS4_ESt4hashIS4_ENSt8__detail18_Mod_range_hashingENSF_20_Default_ranged_hashENSF_20_Prime_rehash_policyELb0ELb0ELb1EE4findERS6_[std::_Hashtable<seqan::String<char, seqan::Alloc<void> >, std::pair<seqan::String<char, seqan::Alloc<void> > const, unsigned int>, std::allocator<std::pair<seqan::String<char, seqan::Alloc<void> > const, unsigned int> >, std::_Select1st<std::pair<seqan::String<char, seqan::Alloc<void> > const, unsigned int> >, std::equal_to<seqan::String<char, seqan::Alloc<void> > >, std::hash<seqan::String<char, seqan::Alloc<void> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true>::find(seqan::String<char, seqan::Alloc<void> > const&)]+0x8a): undefined reference to `std::hash<seqan::String<char, seqan::Alloc<void> > >::operator()(seqan::String<char, seqan::Alloc<void> >) const' collect2: ld gab 1 als Ende-Status zurück _______________________________________________ seqan-dev mailing list seqan-dev@lists.fu-berlin.de https://lists.fu-berlin.de/listinfo/seqan-dev _______________________________________________ seqan-dev mailing list seqan-dev@lists.fu-berlin.de https://lists.fu-berlin.de/listinfo/seqan-dev _______________________________________________ seqan-dev mailing list seqan-dev@lists.fu-berlin.de<mailto:seqan-dev@lists.fu-berlin.de> https://lists.fu-berlin.de/listinfo/seqan-dev |