You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.1 KiB
95 lines
2.1 KiB
// Copyright (c) Microsoft. All rights reserved. |
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
|
|
|
#if !NET_4_6 |
|
using System.Collections.Generic; |
|
|
|
namespace System.Linq.Expressions.Reimplement |
|
{ |
|
/// <summary> |
|
/// A simple hashset, built on Dictionary{K, V} |
|
/// </summary> |
|
internal sealed class Set<T> : ICollection<T> |
|
{ |
|
private readonly Dictionary<T, object> _data; |
|
|
|
internal Set() |
|
{ |
|
_data = new Dictionary<T, object>(); |
|
} |
|
|
|
internal Set(IEqualityComparer<T> comparer) |
|
{ |
|
_data = new Dictionary<T, object>(comparer); |
|
} |
|
|
|
internal Set(IList<T> list) |
|
{ |
|
_data = new Dictionary<T, object>(list.Count); |
|
foreach (var t in list) |
|
{ |
|
Add(t); |
|
} |
|
} |
|
|
|
internal Set(IEnumerable<T> list) |
|
{ |
|
_data = new Dictionary<T, object>(); |
|
foreach (var t in list) |
|
{ |
|
Add(t); |
|
} |
|
} |
|
|
|
internal Set(int capacity) |
|
{ |
|
_data = new Dictionary<T, object>(capacity); |
|
} |
|
|
|
public void Add(T item) |
|
{ |
|
_data[item] = null; |
|
} |
|
|
|
public void Clear() |
|
{ |
|
_data.Clear(); |
|
} |
|
|
|
public bool Contains(T item) |
|
{ |
|
return _data.ContainsKey(item); |
|
} |
|
|
|
public void CopyTo(T[] array, int arrayIndex) |
|
{ |
|
_data.Keys.CopyTo(array, arrayIndex); |
|
} |
|
|
|
public int Count |
|
{ |
|
get { return _data.Count; } |
|
} |
|
|
|
public bool IsReadOnly |
|
{ |
|
get { return false; } |
|
} |
|
|
|
public bool Remove(T item) |
|
{ |
|
return _data.Remove(item); |
|
} |
|
|
|
public IEnumerator<T> GetEnumerator() |
|
{ |
|
return _data.Keys.GetEnumerator(); |
|
} |
|
|
|
Collections.IEnumerator Collections.IEnumerable.GetEnumerator() |
|
{ |
|
return _data.Keys.GetEnumerator(); |
|
} |
|
} |
|
} |
|
#endif |