Containers

  • Thread starter Carlos Martinez Garcia
  • Start date
C

Carlos Martinez Garcia

I need to use a container for finding elements, but the key is composed.

I have read about map and hash_map, but I don't see the diferences.

hash_map uses a hash function, but I don't know it hash function is
important in terms of efficiency.

Which is the best container for that?

Thanks in advance
 
M

Mark P

Carlos said:
I need to use a container for finding elements, but the key is composed.

What do you mean by "composed"?
I have read about map and hash_map, but I don't see the diferences.

A hash_map uses a hash function to place and locate its elements, a map
uses a comparison function to keep its elements sorted and uses binary
search to place and locate them. Assuming you have a good enough hash
function, inserts, finds, and removals on a hash_map are O(1), whereas
they are O(log N) on a map. However if you need to iterate through the
elements in sorted order, then a map is your only option. Also,
hash_map is currently not standard and therefore not necessarily portable.
hash_map uses a hash function, but I don't know it hash function is
important in terms of efficiency.

Naturally, this depends. It can be.
Which is the best container for that?

For what?

-Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top