20 namespace System.Collections.Generic
23 public class SortedSet<T> : ISet<T>, ICollection
25 private readonly SortedList<T, byte> _list;
28 : this(Comparer<T>.Default)
31 public SortedSet(IComparer<T> comparer)
33 _list =
new SortedList<T, byte>(comparer);
36 public T Min {
get {
return (_list.Count) >= 1 ? _list.Keys[0] :
default(T); } }
38 public T Max {
get {
return (_list.Count) >= 1 ? _list.Keys[_list.Count - 1] :
default(T); } }
51 public void CopyTo(T[] array,
int arrayIndex)
53 _list.Keys.CopyTo(array, arrayIndex);
56 public bool Remove(T item)
58 return _list.Remove(item);
61 public bool Contains(T value)
63 return _list.ContainsKey(value);
66 public bool Add(T item)
68 if (!_list.ContainsKey(item))
76 public void UnionWith(IEnumerable<T> other)
78 foreach (var obj
in other)
82 public IEnumerator<T> GetEnumerator()
84 return _list.Keys.GetEnumerator();
87 public IComparer<T> Comparer {
get {
return _list.Comparer; } }
91 get {
return _list.Count; }
94 #region Explicit Interface Implementations
96 void ICollection<T>.Add(T item)
101 void ICollection.CopyTo(Array array,
int index)
103 CopyTo((T[]) array, index);
106 bool ICollection<T>.IsReadOnly
108 get {
return false; }
111 bool ICollection.IsSynchronized
113 get {
return false; }
116 object ICollection.SyncRoot
118 get {
throw new NotSupportedException(); }
121 IEnumerator IEnumerable.GetEnumerator()
123 return GetEnumerator();
126 int ICollection.Count
128 get {
return Count; }
133 #region ISet<T> Implementation
135 void ISet<T>.ExceptWith(IEnumerable<T> other)
137 foreach(var obj
in other)
143 void ISet<T>.IntersectWith(IEnumerable<T> other)
145 throw new NotImplementedException();
148 bool ISet<T>.IsProperSubsetOf(IEnumerable<T> other)
150 throw new NotImplementedException();
153 bool ISet<T>.IsProperSupersetOf(IEnumerable<T> other)
155 throw new NotImplementedException();
158 bool ISet<T>.IsSubsetOf(IEnumerable<T> other)
160 throw new NotImplementedException();
163 bool ISet<T>.IsSupersetOf(IEnumerable<T> other)
165 throw new NotImplementedException();
168 bool ISet<T>.Overlaps(IEnumerable<T> other)
170 throw new NotImplementedException();
173 bool ISet<T>.SetEquals(IEnumerable<T> other)
175 throw new NotImplementedException();
178 void ISet<T>.SymmetricExceptWith(IEnumerable<T> other)
180 throw new NotImplementedException();