// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections; using System.Collections.Generic; namespace EpicGames.Core { /// /// Wrapper around the HashSet container that only allows read operations /// /// Type of element for the hashset [Obsolete("ReadOnlyHashSet is obsolete, please replace with IReadOnlySet")] public class ReadOnlyHashSet : IReadOnlyCollection { /// /// The mutable hashset /// readonly HashSet _inner; /// /// Constructor /// /// The mutable hashset public ReadOnlyHashSet(HashSet inner) { _inner = inner; } /// /// Constructor /// /// Elements for the hash set public ReadOnlyHashSet(IEnumerable elements) { _inner = new HashSet(elements); } /// /// Constructor /// /// Elements for the hash set /// Comparer for elements in the set public ReadOnlyHashSet(IEnumerable elements, IEqualityComparer comparer) { _inner = new HashSet(elements, comparer); } /// /// Number of elements in the set /// public int Count => _inner.Count; /// /// The comparer for elements in the set /// public IEqualityComparer Comparer => _inner.Comparer; /// /// Tests whether a given item is in the set /// /// Item to check for /// True if the item is in the set public bool Contains(T item) { return _inner.Contains(item); } /// /// Gets an enumerator for set elements /// /// Enumerator instance public IEnumerator GetEnumerator() { return _inner.GetEnumerator(); } /// /// Gets an enumerator for set elements /// /// Enumerator instance IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_inner).GetEnumerator(); } /// /// Implicit conversion operator from hashsets /// /// public static implicit operator ReadOnlyHashSet(HashSet hashSet) { return new ReadOnlyHashSet(hashSet); } } }