3
在C#
我喜欢的Dictionary
TryGetValue
方法,因为它可以让我在一个呼叫确定字典包含键和接收值,如果这样:如何在boost :: unordered_map中实现TryGetValue?
Instrument instrument;
if (isinId2Instrument.TryGetValue(isin_id, out instrument))
{
// key exist, instrument contains value
} else {
// key doesn't exist
}
我应该怎么做boost::unordered_map
同样的事情?
只是双检'm.find'将花费'登录N'不'N'? – javapowered 2013-05-01 10:43:13
@javapowered unordered_map <>是一个哈希表。散列表的性能可以在O(1)和O(n)之间的任何位置,具体取决于散列函数和密钥的分布。如果你想O(log n),然后使用std :: map <>。 – 2013-05-01 11:03:19
@brianbeuning我需要log N的平均值。 – javapowered 2013-05-01 11:47:56