具有多个“索引”的标准C++数据结构
问题描述:
C++(或C++ 11)中是否有像set
那样的标准结构或库,但可能有多个key
。具有多个“索引”的标准C++数据结构
即一组std :: pair可以快速查找a
或b
。
所以你可以做这样的事情:
std::string a = "hello";
std::string b = "world";
x.insert(a, b);
x.get<1>("hello") => std::pair("hello", "world"); // (fast lookup)
x.get<2>("world") => std::pair("hello", "world"); // (fast lookup)
基本上就像两个索引数据库表。
我宁可不重新发明轮子,如果已经存在。
一个简单的方法来结合现有的容器,使这个功能的东西也将是很好的。
看看这个例子:http://stackoverflow.com/questions/4450095/maintaining-a-unique-set-of-elements-on-different-criteria-c-stl/4450256#4450256 – AraK