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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:39:01+00:00 2026-06-04T20:39:01+00:00

The unordered_map<> (c++11) uses a hash function to internally organize it’s key-values. The collision

  • 0

The unordered_map<> (c++11) uses a hash function to internally organize it’s key-values. The collision probability is very small (1.f/std:numeric_limits<size_t>::max()).

Is it okay to use an unordered_map<> as a storage container for a heap memory management? That is, if two elements get mixed up (by collision) the stability of the program is destroyed. In my case that would lead to repeatedly calling free() on the same pointer. (SIGSEGV).

Or is the collision probability only important when searching for a key. And it is guaranteed that two different keys always refer to different values?

Follow up question: Say the unordered_map with its standard hash function is not okay for my application. If one wanted to make sure that no collision can occur, and one can limit oneself to a maximum of size_t elements, can one provide her own hash function that returns the argument itself. Something like:

template<class T>
struct Hash
{
  size_t operator()(T t) {
    return (size_t)t;
  }
}

and be sure of no collisions?

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

    Collisions only affect performance, not the contents of the container. unordered_map takes a hash function and an equality function. Two elements can safely have the same hash, and if they compare non-equal then they’re treated as non-equal. They’ll just always be in the same hash bucket. Large buckets harm performance of operations that look in that bucket.

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

Sidebar

Related Questions

I'm trying to create a std::unordered_map, using a user-defined hash function and equality predicate,
Consider unordered_map : template< class Key, class T, class Hash = std::hash<Key>, class KeyEqual
The new C++11 standard has unordered containers. In particular, the std::unordered_map<Key, Value> stores a
class MyObject{ public: void testFunctionMap(){ std::unordered_map<std::string, std::function<void()> > functionMap; std::pair<std::string, std::function<void()> > myPair(print, std::bind(&MyObject::printSomeText,
To support user-defined key types in std::unordered_set<Key> and std::unordered_map<Key, Value> one has to provide
what hash function is being used by boost c++ unordered_map ? I meant what
I'm using an std::unordered_map<key,value> in my implementation. i will be using any of the
I'm trying to form a std::tr1::unordered_map where the key type is a struct that
Now that std has a real hash map in unordered_map , why (or when)
I've a hash table defined like this typedef std::unordered_map<unsigned long long int,unsigned long long

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.