std::map vs. vector of vector

前端 未结 3 773
天命终不由人
天命终不由人 2021-01-26 17:33

I need a container to store a value (int) according to two attributes, source (int) and destination (int) i.e. when a source sends something to a destination, I need to store it

3条回答
  •  忘掉有多难
    2021-01-26 17:53

    I need a container to store a value (int) according to two attributes, source (int) and destination (int)

    std::map, int>
    

    A subsequent process needs to check this container, to see if an element exists in for a particular source, and a particular destination - it will need to differentiate between an empty 'space' and a filled one.

    std::map::find
    

    http://www.cplusplus.com/reference/map/map/find/

    The container has the possibility of being very sparse.

    Use a std::map. The "correct" choice of a container is based on how you need to find things and how you need to insert/delete things. If you want to find things fast, use a map.

提交回复
热议问题