反向地图查找 [英] Reverse map lookup
本文介绍了反向地图查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个1对1的地图。从值中查找键的最好方法是什么?
即
p>
键值
a 1
b 2
c 3
d 4
我想能找到对应于3的那个键。
谢谢!
解决方案
关于它。您可以选择使用两个地图,使用多键地图,例如 Boost多索引库,或执行线性搜索。
更新:最轻巧的开箱即用解决方案似乎< a href =http://www.boost.org/doc/libs/release/libs/bimap/doc/html/index.html> Boost.Bimap ,它代表双向地图。 / p>
I have a 1 to 1 map. What's the best way to find keys from values,
i.e.
For examples if the map is this
KEY VALUE
a 1
b 2
c 3
d 4
I want to be able to find that key corresponding to 3 is C.
Thanks!
解决方案
There isn't much you can do about it. Your have options to work with two maps, use multi-key map like one from Boost Multi-Index library, or do linear search.
UPDATE: The most lightweight out of the box solution seems to be Boost.Bimap, which stands for bi-directional map.
这篇关于反向地图查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文