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

  • SEARCH
  • Home
  • 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 8679017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:52:02+00:00 2026-06-12T20:52:02+00:00

I am using Visual studio 2010 and I am using the C++ 11 feature

  • 0

I am using Visual studio 2010 and I am using the C++ 11 feature std::unordered_map::hash_function() to print the hash values that get computed for each of the key strings.

However I find that internally the entries are stored in random order and not in increasing order of the hashvalues.

In the example below, Dad computes to the lowest hash value and should be the beginning entry of the my_family_height_map, but it is not. And the beginning element is the sis pair which computes to a higher hash value than the Dad.

Cam someone explain why I am seeing this weird behavior?

// unorderedmap_usage.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <unordered_map>
#include <string>
#include <iostream>

int main()
{
    typedef std::unordered_map<std::string, double> height_map;
    height_map my_family_height_map;

    my_family_height_map["Dad"] = 5.10;
    my_family_height_map["Mom"] = 5.3;
    my_family_height_map["Sis"] = 5.3;
    my_family_height_map["Zach"] = 6.2;

    height_map::const_iterator c_it;

    // Print everything in the map
    for(c_it = my_family_height_map.begin(); c_it!= my_family_height_map.end(); ++c_it)
    {
        std::cout << "Hash:" << hasher_func(c_it->first) << "  Person is : " << c_it->first << " - height is " << c_it->second << "\n";
    }
}

O/P:
Hash:572570820 Person is : Sis – height is 5.3
Hash:306541572 Person is : Dad – height is 5.1
Hash:1076885014 Person is : Mom – height is 5.3
Hash:2613037907 Person is : Zach – height is 6.2
Press any key to continue . . .

  • 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-06-12T20:52:03+00:00Added an answer on June 12, 2026 at 8:52 pm

    Unordered map is, as the name suggests, unordered. There is no requirement in the spec that says that entries must be iterated over in order of increasing hashes. Or decreasing hashes. Or anything at all, which is why it’s called “unordered”.1

    If you want the technical details, the hashes have to be turned into bin indices. This is done via some truncation/wrapping/etc algorithm, based on the number of bins in the hash table. That’s why it’s unordered; because the order of iteration is typically the order of bins, which does not have to match with the ordering of hashes.

    1 Technically, it’s called “unordered” because many C++ standard library implementations already shipped with types called hash_map/set/etc. And the committee didn’t want to overlap with them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Visual Studio 2010 RC. Would it be possible that after doing my
I'm using the config file replacement feature of Visual Studio 2010's Publish functionality, as
Visual Studio 2010 has a new feature that is just way cool. You can
I have deployed this application using Visual Studio 2010's Publish feature; it needs to
I am using Visual Studio 2010 along with Team Foundation Server. I know that
When using the built-in Publish feature of Visual Studio 2010 with a web application
I am using WSPBuilder on Visual Studio 2010 to create a feature with a
I was using a Resharper trial in Visual Studio 2010 that expired. After it
I am using Visual Studio 2010, and I know this feature is available in
We are using Visual Studio 2010 connected to Team Foundation Server 2010 and we

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.