Containers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carlos Martinez Garcia

    #1

    Containers

    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
  • Mark P

    #2
    Re: Containers

    Carlos Martinez Garcia wrote:[color=blue]
    > I need to use a container for finding elements, but the key is composed.
    >[/color]

    What do you mean by "composed"?
    [color=blue]
    > I have read about map and hash_map, but I don't see the diferences.
    >[/color]

    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.
    [color=blue]
    > hash_map uses a hash function, but I don't know it hash function is
    > important in terms of efficiency.[/color]

    Naturally, this depends. It can be.
    [color=blue]
    >
    > Which is the best container for that?[/color]

    For what?

    -Mark

    Comment

    Working...