• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How do I write a hash function for an unordered_map that takes a pair as key, but return the same value if I switch the order of the pairs members?

Resolved: How do I write a hash function for an unordered_map that takes a pair as key, but return the same value if I switch the order of the pairs members?

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to create an std::unordered_map that takes a std::pair as key, and returns a size_t as value. The tricky part for me is that I want custom hash function for my map to disregard the order of the members of the key std::pair. I.e:
This is not a clear cut MWE but it’s a cut out of what I’m trying to do in my program:

Answer:

Using a custom class for equality testing:
Note that the above code does what I think you want to do… Also I haven’t tested the code.
Then your map would be declared like that :
By the way, not sure why you are using (nested) pointers…

If you have better answer, please add a comment about this, thank you!

c++
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.