C++ STD::MAP 复杂键搜索
我对库的访问权限有限,因此尽管使用 boost::multi_index 可以解决我的问题,但我无法使用它。
我当前的地图设置是: 该结构包含大量信息,例如我还需要搜索的 INT。我所希望的是这样的结构,以便我可以按 int 或字符串搜索并返回结构值。我假设我必须写下密钥,但是我来这里是为了寻求其他建议。
有想法吗?
I have limited access to libraries so although using boost::multi_index would solve my issue it is something that I cannot use.
My current map setup is:
The structure contains a fair amount of information in it such as an INT that I will also need to search by. What I was hoping was a structure such as so that I can search by int or string and return the structure values. I am assuming that I am going to have to write the key but, was coming here for other suggestions.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有点困惑。您似乎是在说您有这样的构造:
(psudocode)
...并且您希望能够通过 foo_ 的值搜索
Gizmo
?在这种情况下,您有两个主要选择。
1) 只需自己编写一个自定义函子(再次使用 psudocude):
2) 创建 foo_ 值的索引,映射回主
map< 中的
Gizmo
/代码>。这张地图可能看起来像这样...
a
...您每次更新主地图
my_gizmos
时都会维护它。I'm a little confused. You seem to be saying that you have a construct like this:
(psudocode)
...and you want to be able to search for
Gizmo
s by the value offoo_
?In that case, you have 2 main options.
1) Just write a custom functor yourself (again psudocude):
2) Create an index of the
foo_
values, mapping back to theGizmo
in the mainmap
. This map might look something like this...
a
...which you would maintain any time you update the main map,
my_gizmos
.如果您的搜索实际上是窗口查询(意味着您必须返回 [param0_0, peram0_1]x[param1_0, param1_2]x...)中的值,那么您可以使用范围树结构来提高效率。
If your searches actually are windowing queries(meaning you must return values in [param0_0, peram0_1]x[param1_0, param1_2]x...) or so, then you can use range tree structure for efficiency.