class Program
{
static void Main(string[] args)
{
HashSet<string> hash=new HashSet<string> ();
//url列表
StreamReader reader = new StreamReader( "AccessURL.txt", true);
string url = "";
List<string> list = new List<string>();
while (!reader.EndOfStream)
{
url = reader.ReadLine();
list.Add(url);
}
reader.Close();
Dictionary<string,bool> dic=new Dictionary<string,bool> ();
DateTime time1 = DateTime.Now;
foreach(string s in list)
{
hash.Add(s);
}
DateTime time2 = DateTime.Now;
TimeSpan t = new TimeSpan(time2.Ticks - time1.Ticks);
Console.WriteLine("hash add: " + t.Ticks.ToString());
time1 = DateTime.Now;
foreach(string s in list)
{
dic.Add(s,true);
}
time2 = DateTime.Now;
t = new TimeSpan(time2.Ticks - time1.Ticks);
Console.WriteLine("dicadd: "+t.Ticks.ToString());
time1 = DateTime.Now;
foreach (string s in list)
{
hash.Contains(s);
}
time2 = DateTime.Now;
t = new TimeSpan(time2.Ticks - time1.Ticks);
Console.WriteLine("hashfind: " + t.Ticks.ToString());
time1 = DateTime.Now;
foreach (string s in list)
{
dic.ContainsKey(s);
}
time2 = DateTime.Now;
t = new TimeSpan(time2.Ticks - time1.Ticks);
Console.WriteLine("dic find: " + t.Ticks.ToString());
Console.ReadLine();
}
}
运行结果:
hash add: 625000
dicadd: 156250
hashfind: 468750
dic find: 156250
(1)Dictionary适合数据非常有层次性的东西。特别是具有目录结构的东西。Dictionary本身的含义就是词典嘛。
(2)保存URL的时候,应该Dictionary比hashSet快。
保存大量的md5码的时候,Dictionary比hashSet快。
分享到:
相关推荐
主要介绍了C# ArrayList、HashSet、HashTable、List、Dictionary的区别的相关知识点内容,有需要朋友们参考下。
在本篇文章里小编给大家整理的是关于HashTable、HashSet和Dictionary的区别点,需要的朋友们可以学习下。
Remember, class Dictionary is a type of HashSet, so use the inherited methods accordingly. 3. Next, complete the hash function encapsulated in class hash_function in dictionary.h. 4. Then, finish ...
Remember, class Dictionary is a type of HashSet, so use the inherited methods accordingly. 3. Next, complete the hash function encapsulated in class hash_function in dictionary.h. 4. Then, finish ...
数据结构 简单的数据结构,包括HashSet,HashMap,Heap,Red-Black Tree等。
Collection List LinkedList ArrayList Vector Stack Set HashSet Map HashMap Dictionary Hashtable Comparetor 2. Vector和ArrayList、LinkedList区别? Hashtable 和 HashMap之间的区别 LinkedList内部以链表...
Dictionary, Dictionary, int>> words = new Dictionary, Dictionary, int>>(); Dictionary, int> freq = new Dictionary, int>(); Dictionary, double> ps = new Dictionary, double>(); Regex regSplit = ...
Dictionary 内部实现 集合 HashSet 内部实现 HashSet内部基础结构是数组,构造参数为零时不会分配内存 Hashtable Hashtable 内部实现 基础数据结构是bucket, bucket数组来存储数据 new Hashtable(): capacity 初始化...
interface Map<Key> TreeMap<K> HashMap<K> LinkedHashMap<K> Hashtable<K> extends Dictionary<K> - JDK 1.0 接口 Set TreeSet HashSet 树特里================== 问题: 如何使用两个堆栈实现队列? 答案:...
Dictionary -键/值对的集合。 Collection -强类型集合。 ReadOnlyCollection只读包装器集合。 HashSet不含重复元素的高性能值集。 SortedList按键排序的键/值对的集合。 LinkedList双链表。 Queue -对象的...
开始直接输出在C#定义好的数据字典Dictionary,这就是Java与Python的HashMap,之后定义一个存int的List,让用户无限输入这个List的元素,输入到#则停止输入,在输入的过程中遇到不是纯输入,则拒绝这个输入。...
11.2.4哈希集合(HashSet)使用示例343 11.2.5哈希映射类(HashMap)使用示例347 11.2.6有序树(TreeSet)使用示例349 11.2.7有序树映射类(TreeMap)使用示例353 11.2.8枚举(Enum)使用示例355 11.2.9枚举集...