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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:35:21+00:00 2026-05-29T05:35:21+00:00

Consider unordered_map : template< class Key, class T, class Hash = std::hash<Key>, class KeyEqual

  • 0

Consider unordered_map:

template<
    class Key,
    class T,
    class Hash = std::hash<Key>,
    class KeyEqual = std::equal_to<Key>,
    class Allocator = std::allocator< std::pair<const Key, T> >
> class unordered_map;

I know (a==b) is faster than !(a<b) && !(b>a), but since unordered_map does not use std::less<Key> to compare/store the keys in the map, I wonder how can an implementation profit by tree data structures in the most efficient way to read/store different keys in the same bucket. It seems that a convertion from Key to a sort of KeyWrapper with operator<() defined cannot be avoided by any implementation with trees.

  • 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-29T05:35:21+00:00Added an answer on May 29, 2026 at 5:35 am

    You cannot use a tree inside unordered_map, even just within a bucket. unordered_map‘s interface simply does not allow it. The key type is required only to be equality comparable, nothing more. That’s why it’s called an “unordered” map; because there is no specific ordering of elements. To use some kind of binary tree would require a strict weak ordering, which is not required.

    If you want to use a variation of an unordered_map, you may. But it would not be an unordered_map as defined by the standard.

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

Sidebar

Related Questions

Consider the following simple map: class MyCoolMap : public unordered_map<const char *, const char
consider this class: class baseController { /* Action handler array*/ std::unordered_map<unsigned int, baseController*> actionControllers;
Consider the following code: #include <unordered_map> struct A {}; struct T { std::unordered_map<std::string, A>
Consider the following code. I want to specialize std::hash<> used in a Map ,
Consider this code: #include <iostream> using namespace std; class hello{ public: void f(){ cout<<f<<endl;
Consider the following short program: #include <type_traits> #include <iostream> using namespace std; template <typename
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following situation: public class Storage { public T GetSingleByID<T>(long id) where T
Consider the following example of mongo collection: {_id : ObjectId(4f304818884672067f000001), hash : {call_id :

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.