/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * Licensed under the Oculus SDK License Agreement (the "License"); * you may not use the Oculus SDK except in compliance with the License, * which is provided at the time of installation or download, or which * otherwise accompanies this software in either electronic or hard copy form. * * You may obtain a copy of the License at * * https://developer.oculus.com/licenses/oculussdk/ * * Unless required by applicable law or agreed to in writing, the Oculus SDK * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; namespace Oculus.Interaction.Collections { /// /// Exposes a GetEnumerator method with a non-allocating HashSet.Enumerator struct. /// /// /// This is an advanced performance optimization for scenarios where an interface representation of /// a hash set is needed, but the allocations associated with boxing the enumerator as an IEnumerable /// are problematic (for example, because of invocation in per-frame logic as in /// ). In general, iteration over concrete collection /// types avoids the need for this interface; but for scenarios where exposing the full contract of a HashSet /// would be improper (as again in s, where /// should expose the ability to /// _enumerate_ the collection without the ability to _modify_ the collection), this interface and its /// implementing type can fulfill the required contract without unintended /// allocations. /// public interface IEnumerableHashSet : IEnumerable { /// /// Gets the number of elements that are contained in a set. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.count?view=net-8.0#system-collections-generic-hashset-1-count). /// int Count { get; } /// /// Returns a non-allocating enumerator that iterates through an IEnumerableHashSet object. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.getenumerator?view=net-8.0#system-collections-generic-hashset-1-getenumerator). /// new HashSet.Enumerator GetEnumerator(); /// /// Determines whether an IEnumerableHashSet object contains the specified element. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.contains?view=net-8.0#system-collections-generic-hashset-1-contains(-0)). /// bool Contains(T item); /// /// Determines whether an IEnumerableHashSet object is a proper subset of the specified collection. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.ispropersubsetof?view=net-8.0#system-collections-generic-hashset-1-ispropersubsetof(system-collections-generic-ienumerable((-0)))). /// bool IsProperSubsetOf(IEnumerable other); /// /// Determines whether an IEnumerableHashSet object is a proper superset of the specified collection. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.ispropersupersetof?view=net-8.0#system-collections-generic-hashset-1-ispropersupersetof(system-collections-generic-ienumerable((-0)))). /// bool IsProperSupersetOf(IEnumerable other); /// /// Determines whether an IEnumerableHashSet object is a subset of the specified collection. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.issubsetof?view=net-8.0#system-collections-generic-hashset-1-issubsetof(system-collections-generic-ienumerable((-0)))). /// bool IsSubsetOf(IEnumerable other); /// /// Determines whether an IEnumerableHashSet object is a superset of the specified collection. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.issupersetof?view=net-8.0#system-collections-generic-hashset-1-issupersetof(system-collections-generic-ienumerable((-0)))). /// bool IsSupersetOf(IEnumerable other); /// /// Determines whether the current IEnumerableHashSet object and a specified collection share common elements. /// /// /// The implementation of this method in is the built-in method HashSet.Overlaps. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.overlaps?view=net-8.0#system-collections-generic-hashset-1-overlaps(system-collections-generic-ienumerable((-0)))). /// public bool Overlaps(IEnumerable other); /// /// Determines whether an IEnumerableHashSet object and the specified collection contain the same elements. /// /// /// The implementation of this method in is the built-in method HashSet.SetEquals. For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.setequals?view=net-8.0#system-collections-generic-hashset-1-setequals(system-collections-generic-ienumerable((-0)))). /// public bool SetEquals(IEnumerable other); } /// /// A hash set that implements the interface, to use for non-allocating /// iteration of a HashSet. /// /// /// For an overview of the relevance and applicability of this type, see the remarks /// on . /// public class EnumerableHashSet : HashSet, IEnumerableHashSet { /// /// Default constructor, functionally a wrapper for the underlying hash set's equivalent constructor. /// /// /// For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.-ctor?view=net-8.0#system-collections-generic-hashset-1-ctor). /// public EnumerableHashSet() : base() { } /// /// Enumerable constructor, functionally a wrapper for the underlying hash set's equivalent constructor. /// /// /// For more information, please consult the /// [official documentation for HashSet](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.-ctor?view=net-8.0#system-collections-generic-hashset-1-ctor(system-collections-generic-ienumerable((-0)))). /// public EnumerableHashSet(IEnumerable values) : base(values) { } } }