EmptyFrozenSet<T>
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
namespace System.Collections.Frozen
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
internal sealed class EmptyFrozenSet<[System.Runtime.CompilerServices.Nullable(2)] T> : FrozenSet<T>
{
private protected override T[] ItemsCore => Array.Empty<T>();
private protected override int CountCore => 0;
internal EmptyFrozenSet(IEqualityComparer<T> comparer)
: base(comparer)
{
}
private protected override int FindItemIndex(T item)
{
return -1;
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
private protected override Enumerator GetEnumeratorCore()
{
return new Enumerator(Array.Empty<T>());
}
private protected override bool IsProperSubsetOfCore(IEnumerable<T> other)
{
return !OtherIsEmpty(other);
}
private protected override bool IsProperSupersetOfCore(IEnumerable<T> other)
{
return false;
}
private protected override bool IsSubsetOfCore(IEnumerable<T> other)
{
return true;
}
private protected override bool IsSupersetOfCore(IEnumerable<T> other)
{
return OtherIsEmpty(other);
}
private protected override bool OverlapsCore(IEnumerable<T> other)
{
return false;
}
private protected override bool SetEqualsCore(IEnumerable<T> other)
{
return OtherIsEmpty(other);
}
private static bool OtherIsEmpty(IEnumerable<T> other)
{
IReadOnlyCollection<T> readOnlyCollection = other as IReadOnlyCollection<T>;
if (readOnlyCollection == null)
return !Enumerable.Any<T>(other);
return readOnlyCollection.Count == 0;
}
}
}