| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
#if NO_HASHSET |
| 4 |
using System; |
| 5 |
using System.Collections.Generic; |
| 6 |
|
| 7 |
namespace System.Reactive |
| 8 |
{ |
| 9 |
class HashSet<T> |
| 10 |
{ |
| 11 |
private readonly Dictionary<T, object> _set; |
| 12 |
private bool _hasNull; |
| 13 |
|
| 14 |
public HashSet(IEqualityComparer<T> comparer) |
| 15 |
{ |
| 16 |
_set = new Dictionary<T, object>(comparer); |
| 17 |
_hasNull = false; |
| 18 |
} |
| 19 |
|
| 20 |
public bool Add(T value) |
| 21 |
{ |
| 22 |
// |
| 23 |
// Note: The box instruction in the IL will be erased by the JIT in case T is |
| 24 |
// a value type. See GroupBy for more information. |
| 25 |
// |
| 26 |
if (value == null) |
| 27 |
{ |
| 28 |
if (_hasNull) |
| 29 |
return false; |
| 30 |
|
| 31 |
_hasNull = true; |
| 32 |
return true; |
| 33 |
} |
| 34 |
else |
| 35 |
{ |
| 36 |
if (_set.ContainsKey(value)) |
| 37 |
return false; |
| 38 |
|
| 39 |
_set[value] = null; |
| 40 |
return true; |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
#endif |