| | 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 | |
|
| 1521 | 10 | | internal readonly HashSet<T> hashSet = new HashSet<T>(); |
| | 11 | |
|
| 3042 | 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 | | { |
| 1448 | 27 | | hashSet.Add(element); |
| 1448 | 28 | | OnAdded?.Invoke(element); |
| 1435 | 29 | | } |
| | 30 | |
|
| | 31 | | public void Add(IEnumerable<T> elements) |
| | 32 | | { |
| 1694 | 33 | | foreach ( T e in elements ) |
| | 34 | | { |
| 404 | 35 | | Add(e); |
| | 36 | | } |
| 443 | 37 | | } |
| | 38 | |
|
| | 39 | | public bool Remove(T element) |
| | 40 | | { |
| 487 | 41 | | if (!hashSet.Remove(element)) |
| 99 | 42 | | return false; |
| | 43 | |
|
| 388 | 44 | | OnRemoved?.Invoke(element); |
| 388 | 45 | | return true; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public void Remove(IEnumerable<T> elements) |
| | 49 | | { |
| 810 | 50 | | foreach ( T e in elements ) |
| | 51 | | { |
| 146 | 52 | | Remove(e); |
| | 53 | | } |
| 259 | 54 | | } |
| | 55 | |
|
| 0 | 56 | | public int Count() => hashSet.Count; |
| | 57 | |
|
| 718 | 58 | | public bool Contains(T element) => hashSet.Contains(element); |
| | 59 | |
|
| 0 | 60 | | public virtual bool Equals(IEnumerable<T> other) { return EqualityComparer<IEnumerable<T>>.Default.Equals(hashSet, o |
| | 61 | | } |