| | 1 | | using System.Collections; |
| | 2 | | using System.Diagnostics; |
| | 3 | |
|
| | 4 | | namespace Fluorite.Strainer.Collections; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Represents a read-only set of values. |
| | 8 | | /// </summary> |
| | 9 | | /// <typeparam name="T"> |
| | 10 | | /// The type of elements in the hash set. |
| | 11 | | /// </typeparam> |
| | 12 | | [DebuggerDisplay(nameof(Count) + " = {" + nameof(Count) + ",nq}")] |
| | 13 | | public class ReadOnlyHashSet<T> : IReadOnlySet<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable |
| | 14 | | { |
| | 15 | | private readonly HashSet<T> _set; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Initializes a new instance of the <see cref="ReadOnlyHashSet{T}"/> class |
| | 19 | | /// with elements copied from specified collection. |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="collection"> |
| | 22 | | /// The collection of values that will create base for this hash set. |
| | 23 | | /// </param> |
| 14 | 24 | | public ReadOnlyHashSet(IEnumerable<T> collection) |
| | 25 | | { |
| 14 | 26 | | _set = new HashSet<T>(Guard.Against.Null(collection)); |
| 14 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <inheritdoc/> |
| 0 | 30 | | public int Count => _set.Count; |
| | 31 | |
|
| | 32 | | /// <inheritdoc/> |
| 163 | 33 | | public bool Contains(T item) => _set.Contains(item); |
| | 34 | |
|
| | 35 | | /// <inheritdoc/> |
| 0 | 36 | | public IEnumerator GetEnumerator() => _set.GetEnumerator(); |
| | 37 | |
|
| | 38 | | /// <inheritdoc/> |
| 0 | 39 | | public bool IsProperSubsetOf(IEnumerable<T> other) => _set.IsProperSubsetOf(other); |
| | 40 | |
|
| | 41 | | /// <inheritdoc/> |
| 0 | 42 | | public bool IsProperSupersetOf(IEnumerable<T> other) => _set.IsProperSupersetOf(other); |
| | 43 | |
|
| | 44 | | /// <inheritdoc/> |
| 0 | 45 | | public bool IsSubsetOf(IEnumerable<T> other) => _set.IsSubsetOf(other); |
| | 46 | |
|
| | 47 | | /// <inheritdoc/> |
| 0 | 48 | | public bool IsSupersetOf(IEnumerable<T> other) => _set.IsSupersetOf(other); |
| | 49 | |
|
| | 50 | | /// <inheritdoc/> |
| 0 | 51 | | public bool Overlaps(IEnumerable<T> other) => _set.Overlaps(other); |
| | 52 | |
|
| | 53 | | /// <inheritdoc/> |
| 0 | 54 | | public bool SetEquals(IEnumerable<T> other) => _set.SetEquals(other); |
| | 55 | |
|
| 0 | 56 | | IEnumerator<T> IEnumerable<T>.GetEnumerator() => _set.GetEnumerator(); |
| | 57 | | } |