的HashSet< T>与词典< K,V> w.r.t搜索时间查找是否存在项目 [英] HashSet<T> versus Dictionary<K, V> w.r.t searching time to find if an item exists

查看:122
本文介绍了的HashSet< T>与词典< K,V> 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性能测试,取自 here

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

添加1000000个对象)

包含检查一组收集的一半对象

删除一组10000个对象的一半

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

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