哈希集<T>与字典&lt;K,V&gt;w.r.t 搜索时间以查找项目是否存在 [英] HashSet&lt;T&gt; versus Dictionary&lt;K, V&gt; w.r.t searching time to find if an item exists

查看:28
本文介绍了哈希集<T>与字典&lt;K,V&gt;w.r.t 搜索时间以查找项目是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HashSet<T> t = new HashSet<T>();
// add 10 million items


Dictionary<K, V> t = new Dictionary<K, V>();
// add 10 million items.

谁的 .Contains 方法会更快返回?

Whose .Contains method will return quicker?

澄清一下,我的要求是我有 1000 万个对象(嗯,确实是字符串),我需要检查它们是否存在于数据结构中.我永远不会迭代.

Just to clarify, my requirement is I have 10 million objects (well, strings really) that I need to check if they exist in the data structure. I will NEVER iterate.

推荐答案

HashSet vs List vs Dictionary 性能测试,摘自 这里.

HashSet vs List vs Dictionary performance test, taken from here.

添加 1000000 个对象(不检查重复项)

包含对 10000 个集合的一半对象的检查

删除 10000 个集合的一半对象

这篇关于哈希集<T>与字典&lt;K,V&gt;w.r.t 搜索时间以查找项目是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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