Better equality code

This commit is contained in:
Matt Nadareski
2020-08-17 14:57:54 -07:00
parent af7633fea2
commit fafac31ea8
5 changed files with 175 additions and 102 deletions

View File

@@ -1106,6 +1106,26 @@ namespace SabreTools.Library.DatItems
#region Sorting and Merging
/// <summary>
/// Determine if two hashes are equal for the purposes of merging
/// </summary>
/// <param name="firstHash">First hash to compare</param>
/// <param name="secondHash">Second hash to compare</param>
/// <returns>True if either is empty OR the hashes exactly match, false otherwise</returns>
public static bool ConditionalHashEquals(byte[] firstHash, byte[] secondHash)
{
// If either hash is empty, we say they're equal for merging
if (firstHash.IsNullOrEmpty() || secondHash.IsNullOrEmpty())
return true;
// If they're different sizes, they can't match
if (firstHash.Length != secondHash.Length)
return false;
// Otherwise, they need to match exactly
return Enumerable.SequenceEqual(firstHash, secondHash);
}
/// <summary>
/// Merge an arbitrary set of ROMs based on the supplied information
/// </summary>