MoonTools.ECS/src/FilterSignature.cs

70 lines
1.2 KiB
C#
Raw Normal View History

2022-04-08 05:52:03 +00:00
using System;
using MoonTools.ECS.Collections;
2022-03-06 06:12:27 +00:00
namespace MoonTools.ECS;
public struct FilterSignature : IEquatable<FilterSignature>
2022-03-06 06:12:27 +00:00
{
public readonly IndexableSet<TypeId> Included;
public readonly IndexableSet<TypeId> Excluded;
2022-03-06 06:12:27 +00:00
public FilterSignature(IndexableSet<TypeId> included, IndexableSet<TypeId> excluded)
{
Included = included;
Excluded = excluded;
}
2022-03-06 06:12:27 +00:00
public override bool Equals(object? obj)
{
return obj is FilterSignature signature && Equals(signature);
}
2022-03-06 06:12:27 +00:00
public bool Equals(FilterSignature other)
{
foreach (var included in Included)
2022-03-06 06:12:27 +00:00
{
if (!other.Included.Contains(included))
2023-04-05 19:08:24 +00:00
{
return false;
2023-04-05 19:08:24 +00:00
}
2022-03-06 06:12:27 +00:00
}
foreach (var excluded in Excluded)
2022-04-08 05:52:03 +00:00
{
if (!other.Excluded.Contains(excluded))
2022-04-08 05:52:03 +00:00
{
return false;
2022-04-08 05:52:03 +00:00
}
}
2022-04-08 05:52:03 +00:00
return true;
}
2022-04-08 05:52:03 +00:00
public override int GetHashCode()
{
var hashcode = 1;
foreach (var type in Included)
{
hashcode = HashCode.Combine(hashcode, type);
}
foreach (var type in Excluded)
{
hashcode = HashCode.Combine(hashcode, type);
2022-04-08 05:52:03 +00:00
}
return hashcode;
}
public static bool operator ==(FilterSignature left, FilterSignature right)
{
return left.Equals(right);
}
public static bool operator !=(FilterSignature left, FilterSignature right)
{
return !(left == right);
2022-03-06 06:12:27 +00:00
}
}