1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Apache License, Version 2.0, please send an email to
8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Apache License, Version 2.0.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
16 using System.Collections;
17 using System.Collections.Generic;
19 // Note: can't move to Utils because name conflicts with System.Linq.Set
21 namespace Microsoft.Scripting.Ast {
23 namespace System.Linq.Expressions {
27 /// A simple hashset, built on Dictionary{K, V}
29 internal sealed class Set<T> : ICollection<T> {
30 private readonly Dictionary<T, object> _data;
33 _data = new Dictionary<T, object>();
36 internal Set(IEqualityComparer<T> comparer) {
37 _data = new Dictionary<T, object>(comparer);
40 internal Set(IList<T> list) {
41 _data = new Dictionary<T, object>(list.Count);
42 foreach (T t in list) {
47 internal Set(IEnumerable<T> list) {
48 _data = new Dictionary<T, object>();
49 foreach (T t in list) {
54 internal Set(int capacity) {
55 _data = new Dictionary<T, object>(capacity);
58 public void Add(T item) {
66 public bool Contains(T item) {
67 return _data.ContainsKey(item);
70 public void CopyTo(T[] array, int arrayIndex) {
71 _data.Keys.CopyTo(array, arrayIndex);
75 get { return _data.Count; }
78 public bool IsReadOnly {
82 public bool Remove(T item) {
83 return _data.Remove(item);
86 public IEnumerator<T> GetEnumerator() {
87 return _data.Keys.GetEnumerator();
90 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
91 return _data.Keys.GetEnumerator();