4 using System.Collections;
5 using System.Collections.Generic;
7 namespace SiliconStudio.Shaders.Utility
13 public class OrderedSet<T> : ISet<T>, IList<T>
15 #region Constants and Fields
19 private List<T> listSet;
23 #region Constructors and Destructors
31 listSet =
new List<T>();
41 listSet =
new List<T>();
47 #region Public Properties
59 public bool IsReadOnly
69 #region Public Methods
72 public bool Add(T item)
74 if (hashSet.Add(item))
85 return listSet.IndexOf(item);
88 public void Insert(
int index, T item)
90 if (hashSet.Add(item))
92 listSet.Insert(index, item);
98 var array = listSet.ToArray();
99 foreach (var element
in array)
108 var element = listSet[index];
109 hashSet.Remove(element);
110 listSet.RemoveAt(index);
113 public T
this[
int index]
117 return listSet[index];
121 var element = listSet[index];
122 hashSet.Remove(element);
123 listSet[index] = value;
124 if (!hashSet.Add(value))
126 throw new InvalidOperationException(
"Value is already in the set");
141 return hashSet.Contains(item);
145 public void CopyTo(T[] array,
int arrayIndex)
147 listSet.CopyTo(array, arrayIndex);
155 throw new ArgumentNullException(
"other");
166 foreach (T local
in other)
177 return listSet.GetEnumerator();
185 throw new ArgumentNullException(
"other");
188 hashSet.IntersectWith(other);
191 for (
int i = 0; i < listSet.Count && i != hashSet.Count; i++)
193 var item = listSet[i];
194 if (!hashSet.Contains(item))
205 return hashSet.IsProperSubsetOf(other);
211 return hashSet.IsProperSupersetOf(other);
217 return hashSet.IsSubsetOf(other);
223 return hashSet.IsSupersetOf(other);
229 return hashSet.Overlaps(other);
235 if (hashSet.Remove(item))
237 listSet.Remove(item);
247 return hashSet.SetEquals(other);
255 throw new ArgumentNullException(
"other");
258 var temp =
new List<T>(other);
259 hashSet.SymmetricExceptWith(temp);
262 foreach (var item
in temp)
264 int indexOf = listSet.IndexOf(item);
272 for (
int i = 0; i < listSet.Count && i != hashSet.Count; i++)
274 var item = listSet[i];
275 if (!hashSet.Contains(item))
288 throw new ArgumentNullException(
"other");
291 foreach (var item
in other)
299 #region Explicit Interface Methods
308 IEnumerator IEnumerable.GetEnumerator()
310 return GetEnumerator();
void IntersectWith(IEnumerable< T > other)
IEnumerator< T > GetEnumerator()
OrderedSet()
Initializes a new instance of the OrderedSet<T> class.
void UnionWith(IEnumerable< T > other)
bool Overlaps(IEnumerable< T > other)
This is a minimal implementation of the missing HashSet from Silverlight BCL It's nowhere near the re...
void Insert(int index, T item)
bool IsSupersetOf(IEnumerable< T > other)
void ExceptWith(IEnumerable< T > other)
bool SetEquals(IEnumerable< T > other)
bool IsProperSubsetOf(IEnumerable< T > other)
OrderedSet(IEnumerable< T > items)
Initializes a new instance of the OrderedSet<T> class.
void CopyTo(T[] array, int arrayIndex)
bool IsSubsetOf(IEnumerable< T > other)
void SymmetricExceptWith(IEnumerable< T > other)
bool IsProperSupersetOf(IEnumerable< T > other)
void RemoveAll(Func< T, bool > filter)