[英]ordered associative data structure optimised for fast lookup?
I'm looking for a std::map
-esque data structure optimised for fast lookup . 我正在寻找为快速查找而优化的
std::map
-esque数据结构。
One approach would be to implement map's interface utilising a sorted std::vector
as the underlying storage - this will offer fast binary_search
thanks to random-access iterators and cache locality. 一种方法是利用排序的
std::vector
作为基础存储来实现map的接口-由于随机访问迭代器和缓存局部性,这将提供快速的binary_search
。
However, this sounds like reinvention of the wheel. 但是,这听起来像是在重新发明轮子。 Surely something like this already exists?
这样的东西肯定已经存在了吗?
Is there an open-source ordered associative data structure which uses a std::vector for storage? 是否存在使用std :: vector进行存储的开源有序关联数据结构?
Edit: 编辑:
In response to the comments suggesting just use std::map - please read here: http://lafstern.org/matt/col1.pdf 对于建议使用std :: map的评论,请在此处阅读: http : //lafstern.org/matt/col1.pdf
The Boost.Containers library has an ordered map container whose storage is backed by a contiguous array called boost::flat_map
. Boost.Containers库有一个有序的地图容器,其存储由名为
boost::flat_map
的连续数组支持。 Note however that the asymptotic, theoretic complexity is the same as for the standard map
(logarithmic), and the choice which is better depends on many details of the use case: insertions vs. lookups, iterations, iterator invalidation requirements. 但是请注意,渐进的理论复杂度与标准
map
(对数)相同,而更好的选择取决于用例的许多细节 :插入与查找,迭代,迭代器无效要求。
Since the interfaces are very similar, it should be possible to literally replace one by the other via a typedef and profile the relative performances, which is something you absolutely must do. 由于接口非常相似,因此应该有可能通过typedef相互替换,并描述相对性能,这是您绝对必须做的。
Is there an open-source ordered associative data structure which uses a std::vector for storage?
是否存在使用std :: vector进行存储的开源有序关联数据结构?
How about maintaining a sorted vector
? 如何维护排序的
vector
? That way look-up can be fast (binary search, without pointer traversal). 这样可以快速查找(二进制搜索,无需遍历指针)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.