multimap与集的地图 [英] multimap vs map with set

查看:98
本文介绍了multimap与集的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪个更有效率。

I'm wondering which is more efficient.

std::map< String, std::set<int> >

std::multimap< String, int >

EDIT:
我不打算做任何事的普通与这些地图。标准插入,删除,修改,搜索。

I do not plan on doing anything out of the ordinary with these maps. Standard insert, delete, modify, search. The size of each set or multi keyed String shouldn't be more than 100.

推荐答案

这个我相信是依赖于实现的,但是(un)教育的猜测:

This I believe is implementation dependant, but an (un)educated guess:

在实践中,它取决于您将保留在 multimap std :: set 。 A multimap 很可能使用对key(n)搜索键之后的值的线性搜索。如果你有大量的整数值,那么log(n)搜索键,然后是日志(n)搜索的值可能会稍快一点。

In practice it depends on the number of integers that you will be keeping in the multimap or the std::set. A multimap will most likely use a linear search of the values after the log(n) search of the key. If you have a large number of integer values, then the log(n) search of the keys followed by a log(n) search of the values may be slightly faster.

然而,在效率方面,在映射多重映射中存储任何内容与字符串

However, in terms of efficiency, storing anything in a map or multimap with a string key will almost certainly outweigh the differences in either case.

如下所述, multimap 可能会更容易使用,并且更清晰的维护,使其具有明显的优势。

As said below, a multimap will likely be easier to use and more clear to maintain giving it a distinct advantage.

这篇关于multimap与集的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆