wasSharp – Diff between revs 31 and 40
?pathlinks?
Rev 31 | Rev 40 | |||
---|---|---|---|---|
Line 7... | Line 7... | |||
7 | |
7 | |
|
8 | using System; |
8 | using System; |
|
9 | using System.Collections; |
9 | using System.Collections; |
|
10 | using System.Collections.Generic; |
10 | using System.Collections.Generic; |
|
- | 11 | using System.Threading; |
||
Line 11... | Line 12... | |||
11 | using System.Threading; |
12 | using System.Linq; |
|
12 | |
13 | |
|
- | 14 | namespace wasSharp.Collections.Specialized |
||
- | 15 | { |
||
- | 16 | public static class ConcurrentHashSetExtensions |
||
- | 17 | { |
||
- | 18 | public static ConcurrentHashSet<T> ToConcurrentHashSet<T>(this IEnumerable<T> enumerable) |
||
- | 19 | { |
||
- | 20 | return new ConcurrentHashSet<T>(enumerable); |
||
- | 21 | } |
||
13 | namespace wasSharp.Collections.Specialized |
22 | } |
|
14 | { |
23 | |
|
15 | public class ConcurrentHashSet<T> : IDisposable, ICollection<T>, IEnumerable<T>, ISet<T> |
24 | public class ConcurrentHashSet<T> : IDisposable, ICollection<T>, IEnumerable<T>, ISet<T> |
|
16 | { |
25 | { |
|
- | 26 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
||
- | 27 | private readonly HashSet<T> _hashSet = null; |
||
- | 28 | private IEnumerable<string> enumerable; |
||
- | 29 | |
||
- | 30 | public ConcurrentHashSet() |
||
- | 31 | { |
||
- | 32 | _lock.EnterWriteLock(); |
||
- | 33 | try |
||
- | 34 | { |
||
- | 35 | _hashSet = new HashSet<T>(); |
||
- | 36 | } |
||
- | 37 | finally |
||
- | 38 | { |
||
- | 39 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
- | 40 | } |
||
- | 41 | } |
||
- | 42 | |
||
- | 43 | public ConcurrentHashSet(IEqualityComparer<T> stringComparer) |
||
- | 44 | { |
||
- | 45 | _lock.EnterWriteLock(); |
||
- | 46 | try |
||
- | 47 | { |
||
- | 48 | _hashSet = new HashSet<T>(stringComparer); |
||
- | 49 | } |
||
- | 50 | finally |
||
- | 51 | { |
||
- | 52 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
- | 53 | } |
||
- | 54 | } |
||
- | 55 | |
||
- | 56 | public ConcurrentHashSet(IEnumerable<T> enumerable) |
||
- | 57 | { |
||
- | 58 | _lock.EnterWriteLock(); |
||
- | 59 | try |
||
- | 60 | { |
||
- | 61 | _hashSet = new HashSet<T>(); |
||
- | 62 | foreach (var i in enumerable) |
||
- | 63 | { |
||
- | 64 | _hashSet.Add(i); |
||
- | 65 | } |
||
- | 66 | } |
||
- | 67 | finally |
||
- | 68 | { |
||
- | 69 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
Line 17... | Line 70... | |||
17 | private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
70 | } |
|
Line 18... | Line 71... | |||
18 | private readonly HashSet<T> _hashSet = new HashSet<T>(); |
71 | } |
|
19 | |
72 | |
|
Line 67... | Line 120... | |||
67 | } |
120 | } |
|
68 | finally |
121 | finally |
|
69 | { |
122 | { |
|
70 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
123 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
|
71 | } |
124 | } |
|
- | 125 | } |
||
- | 126 | |
||
- | 127 | public int RemoveWhere(Predicate<T> match) |
||
- | 128 | { |
||
- | 129 | _lock.EnterWriteLock(); |
||
- | 130 | try |
||
- | 131 | { |
||
- | 132 | return _hashSet.RemoveWhere(match); |
||
- | 133 | } |
||
- | 134 | finally |
||
- | 135 | { |
||
- | 136 | if (_lock.IsWriteLockHeld) _lock.ExitWriteLock(); |
||
- | 137 | } |
||
72 | } |
138 | } |
|
Line 73... | Line 139... | |||
73 | |
139 | |
|
74 | public int Count |
140 | public int Count |
|
75 | { |
141 | { |