]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/csharp/src/Collections/THashSet.cs
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / csharp / src / Collections / THashSet.cs
CommitLineData
f67539c2
TL
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20using System;
21using System.Collections;
22using System.Collections.Generic;
23
24#if SILVERLIGHT
25using System.Runtime.Serialization;
26#endif
27
28namespace Thrift.Collections
29{
30#if SILVERLIGHT
31 [DataContract]
32#else
33 [Serializable]
34#endif
35 public class THashSet<T> : ICollection<T>
36 {
37#if NET_2_0 || SILVERLIGHT
38#if SILVERLIGHT
39 [DataMember]
40#endif
41 TDictSet<T> set = new TDictSet<T>();
42#else
43 HashSet<T> set = new HashSet<T>();
44#endif
45 public int Count
46 {
47 get { return set.Count; }
48 }
49
50 public bool IsReadOnly
51 {
52 get { return false; }
53 }
54
55 public void Add(T item)
56 {
57 set.Add(item);
58 }
59
60 public void Clear()
61 {
62 set.Clear();
63 }
64
65 public bool Contains(T item)
66 {
67 return set.Contains(item);
68 }
69
70 public void CopyTo(T[] array, int arrayIndex)
71 {
72 set.CopyTo(array, arrayIndex);
73 }
74
75 public IEnumerator GetEnumerator()
76 {
77 return set.GetEnumerator();
78 }
79
80 IEnumerator<T> IEnumerable<T>.GetEnumerator()
81 {
82 return ((IEnumerable<T>)set).GetEnumerator();
83 }
84
85 public bool Remove(T item)
86 {
87 return set.Remove(item);
88 }
89
90#if NET_2_0 || SILVERLIGHT
91#if SILVERLIGHT
92 [DataContract]
93#endif
94 private class TDictSet<V> : ICollection<V>
95 {
96#if SILVERLIGHT
97 [DataMember]
98#endif
99 Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>();
100
101 public int Count
102 {
103 get { return dict.Count; }
104 }
105
106 public bool IsReadOnly
107 {
108 get { return false; }
109 }
110
111 public IEnumerator GetEnumerator()
112 {
113 return ((IEnumerable)dict.Keys).GetEnumerator();
114 }
115
116 IEnumerator<V> IEnumerable<V>.GetEnumerator()
117 {
118 return dict.Keys.GetEnumerator();
119 }
120
121 public bool Add(V item)
122 {
123 if (!dict.ContainsKey(item))
124 {
125 dict[item] = this;
126 return true;
127 }
128
129 return false;
130 }
131
132 void ICollection<V>.Add(V item)
133 {
134 Add(item);
135 }
136
137 public void Clear()
138 {
139 dict.Clear();
140 }
141
142 public bool Contains(V item)
143 {
144 return dict.ContainsKey(item);
145 }
146
147 public void CopyTo(V[] array, int arrayIndex)
148 {
149 dict.Keys.CopyTo(array, arrayIndex);
150 }
151
152 public bool Remove(V item)
153 {
154 return dict.Remove(item);
155 }
156 }
157#endif
158 }
159
160}