Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6674309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:43:47+00:00 2026-05-26T03:43:47+00:00

I am using an unordered_map<float, unsigned short> to implement a hash table in C++.

  • 0

I am using an unordered_map<float, unsigned short> to implement a hash table in C++.

I know that using floats as keys to a hash table is a bad idea under most circumstances because comparing them is error-prone. However, under these circumstances, I am reading the floats in from large files and their precision is known and constant.

However, I would like to know the details of how unordered_map is hashing my floats in order to estimate collision frequency. I am not overriding the default hash implementation when I create the unordered_map. According to the documentation, the default hash function is std::hash<Key>. Which in my case is std::hash<float>. However, when I look at the std::hash documentation, it is only defined for “template arguments of type char*, const char*, crope, wrope, and the built-in integral types”.

Does anyone know what function is being called to hash the values as I add them to the unordered_map?

unordered_map – http://msdn.microsoft.com/en-us/library/bb982522.aspx

std::hash – http://www.sgi.com/tech/stl/hash.html#1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:43:48+00:00Added an answer on May 26, 2026 at 3:43 am

    According to the C++11 standard, float is supported for std::hash as well. The actual hash function is implementation dependent, so even if you can figure out collision frequency for your current compiler a newer version or a different compiler may implement a different hash function. Here is the full list of std::hash specializations:

    template <> struct hash<bool>;
    template <> struct hash<char>;
    template <> struct hash<signed char>;
    template <> struct hash<unsigned char>;
    template <> struct hash<char16_t>;
    template <> struct hash<char32_t>;
    template <> struct hash<wchar_t>;
    template <> struct hash<short>;
    template <> struct hash<unsigned short>;
    template <> struct hash<int>;
    template <> struct hash<unsigned int>;
    template <> struct hash<long>;
    template <> struct hash<unsigned long>;
    template <> struct hash<long long>;
    template <> struct hash<unsigned long long>;
    template <> struct hash<float>;
    template <> struct hash<double>;
    template <> struct hash<long double>;
    template <class T> struct hash<T*>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a hash table defined like this typedef std::unordered_map<unsigned long long int,unsigned long long
I'm using ColdFusion to populate a template that includes HTML unordered lists ( <ul>
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have a problem putting data into an unordered_map using a struct as key:
I have the following code: #include <iostream> #include boost/unordered_map.hpp using namespace std; using namespace
I'm using Boost's implementation of a hash map in a project right now, and
I am looking for a template for hash map that i can rely on,
#include <iostream> #include <string> #include <unordered_map> using namespace std; int main() { unordered_map< int,
I recently discovered that the implementation of the hash map in C++ will be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.