diff --git a/src/ObservableCollections/ObservableHashSet.Views.cs b/src/ObservableCollections/ObservableHashSet.Views.cs new file mode 100644 index 0000000..04838f2 --- /dev/null +++ b/src/ObservableCollections/ObservableHashSet.Views.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace ObservableCollections +{ + public sealed partial class ObservableHashSet : IReadOnlyCollection, IObservableCollection + { + // TODO: + public ISynchronizedView CreateSortedView(Func identitySelector, Func transform, IComparer comparer) where TKey : notnull + { + throw new NotImplementedException(); + } + + public ISynchronizedView CreateSortedView(Func identitySelector, Func transform, IComparer viewComparer) where TKey : notnull + { + throw new NotImplementedException(); + } + + public ISynchronizedView CreateView(Func transform, bool reverse = false) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/ObservableCollections/ObservableHashSet.cs b/src/ObservableCollections/ObservableHashSet.cs index 821ea3d..fced310 100644 --- a/src/ObservableCollections/ObservableHashSet.cs +++ b/src/ObservableCollections/ObservableHashSet.cs @@ -1,15 +1,112 @@ -using System.Collections.Generic; +using ObservableCollections.Internal; +using System.Collections; +using System.Collections.Generic; namespace ObservableCollections { - public sealed partial class ObservableHashSet + // can not implements ISet because set operation can not get added/removed values. + public sealed partial class ObservableHashSet : IReadOnlySet, IReadOnlyCollection, IObservableCollection { - //// TODO:not yet - //readonly LinkedList list; + readonly HashSet set; + public readonly object SyncRoot = new object(); - //public ObservableHashSet(LinkedList list) - //{ - // this.list = list; - //} + public ObservableHashSet() + { + this.set = new HashSet(); + } + + public ObservableHashSet(int capacity) + { + this.set = new HashSet(capacity); + } + + public ObservableHashSet(IEnumerable collection) + { + this.set = new HashSet(collection); + } + + public event NotifyCollectionChangedEventHandler? CollectionChanged; + + public int Count + { + get + { + lock (SyncRoot) + { + return set.Count; + } + } + } + + public bool IsReadOnly => false; + + // TODO: Add, Remove, Set operations. + + + public bool Contains(T item) + { + lock (SyncRoot) + { + return set.Contains(item); + } + } + + public bool IsProperSubsetOf(IEnumerable other) + { + lock (SyncRoot) + { + return set.IsProperSubsetOf(other); + } + } + + public bool IsProperSupersetOf(IEnumerable other) + { + lock (SyncRoot) + { + return set.IsProperSupersetOf(other); + } + } + + public bool IsSubsetOf(IEnumerable other) + { + lock (SyncRoot) + { + return set.IsSubsetOf(other); + } + } + + public bool IsSupersetOf(IEnumerable other) + { + lock (SyncRoot) + { + return set.IsSupersetOf(other); + } + } + + public bool Overlaps(IEnumerable other) + { + lock (SyncRoot) + { + return set.Overlaps(other); + } + } + + public bool SetEquals(IEnumerable other) + { + lock (SyncRoot) + { + return set.SetEquals(other); + } + } + + public IEnumerator GetEnumerator() + { + return new SynchronizedEnumerator(SyncRoot, set.GetEnumerator()); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } diff --git a/src/ObservableCollections/ObservableQueue.View.cs b/src/ObservableCollections/ObservableQueue.Views.cs similarity index 100% rename from src/ObservableCollections/ObservableQueue.View.cs rename to src/ObservableCollections/ObservableQueue.Views.cs diff --git a/src/ObservableCollections/ObservableStack.View.cs b/src/ObservableCollections/ObservableStack.Views.cs similarity index 100% rename from src/ObservableCollections/ObservableStack.View.cs rename to src/ObservableCollections/ObservableStack.Views.cs