是否已经有一些基于std :: vector的set / map实现? [英] Is there already some std::vector based set/map implementation?
问题描述
对于小集合或者映射,通常使用排序的向量而不是基于树的 set
/ map> code> - 特别是像5-10元素。 LLVM有一些类本着这种精神,但没有真正的适配器将提供
std: : std :: vector
任何
编辑:感谢所有的替代想法,但我真的感兴趣的一个基于矢量的集合/地图。我有特定的情况下,我倾向于创建大量的集/地图,其中通常包含少于10个元素,我真的想减少内存压力。考虑例如三角形网格中的顶点的相邻边,你可以容易地得到10万套3-4个元素。
我推荐一个名为 Loki 。
它有一个关联容器的基于向量的实现,它是std :: map的一个替代,称为 AssocVector 。
它提供了更好的访问元素的性能删除)。
这本图书馆是由 Andrei Alexandrescu 现代C ++设计作者。
它还包含一些其他真正漂亮的东西。
For small sets or maps, it's usually much faster to just use a sorted vector, instead of the tree-based set
/map
- especially for something like 5-10 elements. LLVM has some classes in that spirit, but no real adapter that would provide a std::map
like interface backed up with a std::vector
.
Any (free) implementation of this out there?
Edit: Thanks for all the alternative ideas, but I'm really interested in a vector based set/map. I do have specific cases where I tend to create huge amounts of sets/maps which contain usually less than 10 elements, and I do really want to have less memory pressure. Think about for example neighbor edges for a vertex in a triangle mesh, you easily wind up with 100k sets of 3-4 elements each.
I just stumbled upon your question, hope its not too late.
I recommend a great (open source) library named Loki. It has a vector based implementation of an associative container that is a drop-in replacement for std::map, called AssocVector.
It offers better performance for accessing elements (and worst performance for insertions/deletions).
The library was written by Andrei Alexandrescu author of Modern C++ Design.
It also contains some other really nifty stuff.
这篇关于是否已经有一些基于std :: vector的set / map实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!