C++ map insertion and lookup performance and storage overhead

前端 未结 8 2033
旧巷少年郎
旧巷少年郎 2021-02-02 10:47

I would like to store a mapping of an integer key to a float value in-memory.

I have roughly 130 million keys (and, accordingly, 130 million v

8条回答
  •  独厮守ぢ
    2021-02-02 11:39

    If your input is sorted, you should try just a vector and a binary search (i.e., lower_bound()). This might prove adaquate (it is also O(log n)). Depending on the distribution of your keys and the hash function used, a hash_map might work as well. I think this is tr1::unordered_map in gcc.

提交回复
热议问题