[runtime] Emit the necessary left shift anding in the LambdaCompiler
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Compiler / Set.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
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.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 using System.Collections;
17 using System.Collections.Generic;
18
19 // Note: can't move to Utils because name conflicts with System.Linq.Set
20 #if !FEATURE_CORE_DLR
21 namespace Microsoft.Scripting.Ast {
22 #else
23 namespace System.Linq.Expressions {
24 #endif
25
26     /// <summary>
27     /// A simple hashset, built on Dictionary{K, V}
28     /// </summary>
29     internal sealed class Set<T> : ICollection<T> {
30         private readonly Dictionary<T, object> _data;
31
32         internal Set() {
33             _data = new Dictionary<T, object>();
34         }
35
36         internal Set(IEqualityComparer<T> comparer) {
37             _data = new Dictionary<T, object>(comparer);
38         }
39
40         internal Set(IList<T> list) {
41             _data = new Dictionary<T, object>(list.Count);
42             foreach (T t in list) {
43                 Add(t);
44             }
45         }
46
47         internal Set(IEnumerable<T> list) {
48             _data = new Dictionary<T, object>();
49             foreach (T t in list) {
50                 Add(t);
51             }
52         }
53
54         internal Set(int capacity) {
55             _data = new Dictionary<T, object>(capacity);
56         }
57
58         public void Add(T item) {
59             _data[item] = null;
60         }
61
62         public void Clear() {
63             _data.Clear();
64         }
65
66         public bool Contains(T item) {
67             return _data.ContainsKey(item);
68         }
69
70         public void CopyTo(T[] array, int arrayIndex) {
71             _data.Keys.CopyTo(array, arrayIndex);
72         }
73
74         public int Count {
75             get { return _data.Count; }
76         }
77
78         public bool IsReadOnly {
79             get { return false; }
80         }
81
82         public bool Remove(T item) {
83             return _data.Remove(item);
84         }
85
86         public IEnumerator<T> GetEnumerator() {
87             return _data.Keys.GetEnumerator();
88         }
89
90         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
91             return _data.Keys.GetEnumerator();
92         }
93     }
94 }