| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | |
|
| | 4 | | public class BaseHashSet<T> : IBaseCollection<T>, IEquatable<IEnumerable<T>> |
| | 5 | | { |
| | 6 | | public event Action<IEnumerable<T>> OnSet; |
| | 7 | | public event Action<T> OnAdded; |
| | 8 | | public event Action<T> OnRemoved; |
| | 9 | |
|
| 416 | 10 | | internal readonly HashSet<T> hashSet = new HashSet<T>(); |
| | 11 | |
|
| 832 | 12 | | public BaseHashSet() { } |
| 0 | 13 | | public BaseHashSet(IEnumerable<T> elements) { hashSet = new HashSet<T>(elements); } |
| | 14 | |
|
| 0 | 15 | | public IEnumerable<T> Get() => hashSet; |
| | 16 | |
|
| | 17 | | public void Set(IEnumerable<T> elements) |
| | 18 | | { |
| 0 | 19 | | hashSet.Clear(); |
| 0 | 20 | | hashSet.UnionWith(elements); |
| | 21 | |
|
| 0 | 22 | | OnSet?.Invoke(hashSet); |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | public void Add(T element) |
| | 26 | | { |
| 278 | 27 | | hashSet.Add(element); |
| 278 | 28 | | OnAdded?.Invoke(element); |
| 278 | 29 | | } |
| | 30 | |
|
| | 31 | | public bool Remove(T element) |
| | 32 | | { |
| 271 | 33 | | if (!hashSet.Remove(element)) |
| 0 | 34 | | return false; |
| | 35 | |
|
| 271 | 36 | | OnRemoved?.Invoke(element); |
| 271 | 37 | | return true; |
| | 38 | | } |
| | 39 | |
|
| 0 | 40 | | public int Count() => hashSet.Count; |
| | 41 | |
|
| 549 | 42 | | public bool Contains(T element) => hashSet.Contains(element); |
| | 43 | |
|
| 0 | 44 | | public virtual bool Equals(IEnumerable<T> other) { return EqualityComparer<IEnumerable<T>>.Default.Equals(hashSet, o |
| | 45 | | } |