Containers

Discussion in 'C++' started by Carlos Martinez Garcia, Mar 21, 2006.

  1. 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
    Carlos Martinez Garcia, Mar 21, 2006
    #1
    1. Advertising

  2. Carlos Martinez Garcia

    Mark P Guest

    Carlos Martinez Garcia wrote:
    > 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
    Mark P, Mar 21, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Westerfield

    Highlighing Text in non-Focussed Containers

    Mike Westerfield, Dec 6, 2003, in forum: Java
    Replies:
    1
    Views:
    414
    Kleopatra
    Dec 8, 2003
  2. milkyway
    Replies:
    2
    Views:
    1,631
    milkyway
    Dec 16, 2004
  3. Replies:
    0
    Views:
    416
  4. Replies:
    7
    Views:
    553
    Pete Becker
    Jan 25, 2008
  5. Sebastian Mach
    Replies:
    5
    Views:
    311
Loading...

Share This Page