forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSet.cs
More file actions
88 lines (74 loc) · 1.95 KB
/
HashSet.cs
File metadata and controls
88 lines (74 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// https://github.com/ServiceStack/ServiceStack.Text
// ServiceStack.Text: .NET C# POCO JSON, JSV and CSV Text Serializers.
//
// Authors:
// Demis Bellot (demis.bellot@gmail.com)
// Mijail Cisneros (cisneros@mijail.ru)
//
// Copyright 2012 Liquidbit Ltd.
//
// Licensed under the same terms of ServiceStack: new BSD license.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ServiceStack.Text.WP
{
///<summary>
/// A hashset implementation that uses an IDictionary
///</summary>
public class HashSet<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{
private readonly Dictionary<T, short> _dict;
public HashSet()
{
_dict = new Dictionary<T, short>();
}
public HashSet(IEnumerable<T> collection)
{
if (collection == null)
throw new ArgumentNullException("collection");
_dict = new Dictionary<T, short>(collection.Count());
foreach (T item in collection)
Add(item);
}
public void Add(T item)
{
_dict.Add(item, 0);
}
public void Clear()
{
_dict.Clear();
}
public bool Contains(T item)
{
return _dict.ContainsKey(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
_dict.Keys.CopyTo(array, arrayIndex);
}
public bool Remove(T item)
{
return _dict.Remove(item);
}
public IEnumerator<T> GetEnumerator()
{
return _dict.Keys.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _dict.Keys.GetEnumerator();
}
public int Count
{
get { return _dict.Keys.Count(); }
}
public bool IsReadOnly
{
get { return false; }
}
}
}