forked from microsoft/VFSForGit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrentHashSet.cs
More file actions
57 lines (47 loc) · 1.34 KB
/
ConcurrentHashSet.cs
File metadata and controls
57 lines (47 loc) · 1.34 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
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace GVFS.Common
{
public class ConcurrentHashSet<T> : IEnumerable<T>
{
private ConcurrentDictionary<T, bool> dictionary;
public ConcurrentHashSet()
{
this.dictionary = new ConcurrentDictionary<T, bool>();
}
public ConcurrentHashSet(IEqualityComparer<T> comparer)
{
this.dictionary = new ConcurrentDictionary<T, bool>(comparer);
}
public int Count
{
get { return this.dictionary.Count; }
}
public bool Add(T entry)
{
return this.dictionary.TryAdd(entry, true);
}
public bool Contains(T item)
{
return this.dictionary.ContainsKey(item);
}
public void Clear()
{
this.dictionary.Clear();
}
public IEnumerator<T> GetEnumerator()
{
return this.dictionary.Keys.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public bool TryRemove(T key)
{
bool value;
return this.dictionary.TryRemove(key, out value);
}
}
}