Cost of using std::map with std::string keys vs int keys?

前端 未结 6 1652
礼貌的吻别
礼貌的吻别 2020-12-06 01:43

I know that the individual map queries take a maximum of log(N) time. However I was wondering, I have seen a lot of examples that use strings as map keys. What is the perfor

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 02:17

    The cost is ofcourse that ints can be compared in real O(1) time whereas strings are compared in O(n) time (n being the maximal shared prefix). Also, the storage of strings consumes more space than that of integers. Other than these apparent differences, there's no major performance cost.

提交回复
热议问题