向量对而不是向量对? [英] Pair of vectors instead of a vector<pair>?

查看:93
本文介绍了向量对而不是向量对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个实现与std :: map和multimap类似的库,但没有树,而是向量,如pair<vector<key>,vector<value>>.库必须使向量保持同步和排序.

I'm looking for a lib that would implement something similar to std::map and multimap, but without tree but vectors instead, like a pair<vector<key>,vector<value>>. The lib would have to keep the vectors synchronized and sorted.

我想比较一下地图,vector<pair<key,value>>和此类库的性能.我不会尝试建立一个通用基准,我只想让我的应用程序更快.

I'd like to compare the performance of maps, vector<pair<key,value>> and such a lib. I'm not going to try to make a general benchmark, I only want what's faster for my application.

我可以像其他所有人一样使用地图,但是-我知道我在说什么-我担心太多的缓存未命中.我的狂热,毫无根据的猜测是,我的应用程序将执行更紧凑,更连续的键,从而使我的应用程序进行少量,分组的插入以及许多分散的搜索,就可以受益.

I could just use map like everyone else, but -and I don't know I'm talking about- I fear for too many cache misses. My wild, uneducated guess is that my app, doing few, grouped inserts and many scattered searches, would benefit from more compact and contiguous keys.

事实上,如果我要编写代码,我将使用两个类来完成.一个未排序的版本仅允许快速的push_back插入,然后转换为一个排序的版本,该版本将采用未排序的版本,对其进行排序,也许检查重复性,然后允许快速搜索和较慢的排序插入.这实际上是Scott Meyers的Effective STL的第23项:考虑用排序后的向量替换关联容器".

As a matter of fact, if I was to code the thing, I'd do it with two classes. An unsorted version with only fast, push_back inserts permitted, then a transformation into a sorted version that would take the unsorted version, sort it, maybe check for duplicity, and then allow fast searches and slower, sorted inserts. This is actually Scott Meyers' Effective STL's Item 23: "Consider replacing associative containers with sorted vectors".

编辑:如Boost文档所指出的有关

As pointed out by the Boost documentation about flat_(multi)map/set, Matt Austern, not Scott Meyers first suggested replacing maps and sets with vectors: http://lafstern.org/matt/col1.pdf

推荐答案

也许您正在寻找类似

Maybe you are looking something like flat_(multi)map/set from Boost.Container ?

这篇关于向量对而不是向量对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆