summaryrefslogtreecommitdiff
path: root/csharp/src/Ice/HashSet.cs
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2015-03-21 15:35:40 -0230
committerMatthew Newhook <matthew@zeroc.com>2015-03-21 15:35:40 -0230
commit630a37d2fe66f24518299e705f958b571803c522 (patch)
tree969723791bdc4d73bb099c19d45554d0ca241ad9 /csharp/src/Ice/HashSet.cs
parentFix some README.md markdown formatting (diff)
downloadice-630a37d2fe66f24518299e705f958b571803c522.tar.bz2
ice-630a37d2fe66f24518299e705f958b571803c522.tar.xz
ice-630a37d2fe66f24518299e705f958b571803c522.zip
py -> python
rb -> ruby objc -> objective-c cs -> csharp
Diffstat (limited to 'csharp/src/Ice/HashSet.cs')
-rw-r--r--csharp/src/Ice/HashSet.cs114
1 files changed, 114 insertions, 0 deletions
diff --git a/csharp/src/Ice/HashSet.cs b/csharp/src/Ice/HashSet.cs
new file mode 100644
index 00000000000..813633d69b7
--- /dev/null
+++ b/csharp/src/Ice/HashSet.cs
@@ -0,0 +1,114 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#if COMPACT
+
+//
+// System.Collections.Generic.HashSet is not available in the .NET Compact Framework.
+// This class is a minimal implementation that provides only the methods required by
+// Ice internals.
+//
+using System;
+using System.Collections.Generic;
+
+namespace IceInternal
+{
+ public class HashSet<T> : ICollection<T>
+ {
+ public HashSet()
+ {
+ entries_ = new Dictionary<T, bool>();
+ }
+
+ public HashSet(int capacity)
+ {
+ entries_ = new Dictionary<T, bool>(capacity);
+ }
+
+ void ICollection<T>.Add(T item)
+ {
+ try
+ {
+ entries_.Add(item, false);
+ }
+ catch(ArgumentException)
+ {
+ // Item already present.
+ }
+ }
+
+ public bool Add(T item)
+ {
+ try
+ {
+ entries_.Add(item, false);
+ }
+ catch(ArgumentException)
+ {
+ return false; // Item already present.
+ }
+ return true;
+ }
+
+ public void Clear()
+ {
+ entries_.Clear();
+ }
+
+ public bool Contains(T item)
+ {
+ return entries_.ContainsKey(item);
+ }
+
+ public void CopyTo(T[] a, int idx)
+ {
+ entries_.Keys.CopyTo(a, idx);
+ }
+
+ public void CopyTo(T[] a)
+ {
+ entries_.Keys.CopyTo(a, 0);
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return entries_.Keys.GetEnumerator();
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return entries_.Keys.GetEnumerator();
+ }
+
+ public bool Remove(T item)
+ {
+ return entries_.Remove(item);
+ }
+
+ public int Count
+ {
+ get
+ {
+ return entries_.Count;
+ }
+ }
+
+ public bool IsReadOnly
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ private Dictionary<T, bool> entries_;
+ }
+}
+
+#endif