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 7057851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:02:32+00:00 2026-05-28T04:02:32+00:00

The new C++11 standard has unordered containers. In particular, the std::unordered_map<Key, Value> stores a

  • 0

The new C++11 standard has unordered containers. In particular, the std::unordered_map<Key, Value> stores a std::pair<Key, Value> in a location based on std::hash<Key> (default hash function). Similarly, the std::unordered_set<Key> stores a Key in a location based on std::hash<Key>.

My question is: how can one store only the Value of a Key-Value pair, in a location based on std::hash<Key>? This would be useful if one uses a perfect hash function, i.e. one for which different Keys map to different hash indices (so there is never collision resolution required).

An unordered_set only uses the key, and an unordered_map uses both the key and the value, so the unordered STL containers in the new C++11 standard do not seem to allow such customization. What would be a good way to get such a data structure from the existing STL containers?

More generally, how can one store a std::pair<T, Value> in a location based on std::hash<Key>, where T is a type representing a signature of the Key? E.g. if Key is a large data structure, I would like to compute a 64-bit hash key and split this into two 32 bit parts: the upper 32 bits together with the Value form a std::pair<uint32_t, Value>, and the lower 32 bits determine the location where this pair is stored.

An application where this would be useful is e.g. computer chess, where a position (several kilobytes in some programs) as the Key type is hashed into a 64-bit key, of which only the upper 32 bits and some search related information as the Value type are stored as a std::pair (usually only 16 bytes in total) in a location based on the lower 32 bits of the hash key.

  • 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-28T04:02:32+00:00Added an answer on May 28, 2026 at 4:02 am

    There is no general-purpose way to perform operations on a hash without continuous access to the hash values. For example, suppose the hash internally uses a tree. To add a new node to the hash, you need to compare its hash value to the hash value of existing nodes on the tree. How can you do that if you didn’t store their values in the tree?

    What you’re asking for is probably not impossible, but none of the typical hashing algorithms can do it. And there doesn’t seem to be any point anyway, you have to store something to make the collection traversable, and it’s hard to see how something other than the hash could ever work as well as the hash, since that’s what you’re searching for.

    If the hash is “too big”, use a hash of the hash. (Of course, then you have to deal with hash collisions.)

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

Sidebar

Related Questions

I'm about to start creating a new website that has standard user management (customers
Standard new rails app has issue showing the rails.png ActionController::RoutingError (No route matches [GET]
I have a web app which has standard things for learning based app like
I have two database tables: 'MyTable' which has a standard auto-incrementing primary key integer
I am just a bit curious about the new function std::move() that has just
Now that the new c++11 standard has made changes in how sequence points are
I'm attempting to use the new standard way of loading seed data in Rails
I'm new to Standard ML and I'm trying to get my head around the
I am relatively new to web services and am wondering what the standard best
Here's a standard scenario: if(string.IsNullOrEmpty(Configuration.AppSettings[foobar])) throw new SomeStandardException(Application not configured correctly, bozo.); The problem

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.