我目前有很多看起来像这样的代码:
std::unordered_map<int,int> my_dict;
.
.
.
// If the key does exist in the dictionary
if(my_dict.count(key) == 1){
my_dict[key] = value;
}
// If its a new key
else{
my_dict.insert(std::make_pair(key,value));
}
有什么方法可以通过每次覆盖值来加快速度吗?
原文由 user997112 发布,翻译遵循 CC BY-SA 4.0 许可协议
您只需这样做(对于
map
和unordered_map
)