gpt4 book ai didi

c++ - 通过键和值搜索对称关联数组

转载 作者:行者123 更新时间:2023-11-28 01:10:58 24 4
gpt4 key购买 nike

我需要描述一个要在其中搜索的关联数组,可以使用键和值。具有添加、删除、getBy1st(按键搜索)、getBy2nd(按值搜索)功能。例如在 C++ 中:

symmap<std::string, int> m;  
m.insert(make_pair<std::string,int> ("hello", 1));
m.insert(make_pair<std::string,int> ("wow", 2));
...
m.getBy1st("hello"); // returns 1
m.getBy2nd(2);// returns "wow"

它应该适用于 O(log(n)) 并存储在 std::pair 中。我不能决定用什么数据结构来存储。也许我可以使用 rb-tree 的一些变体来存储它?

最佳答案

这听起来很像 Boost.Bimap .

关于c++ - 通过键和值搜索对称关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3273671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com