Skip to content

Commit

Permalink
Impl ArrayChangelog comparer
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed May 6, 2024
1 parent 8c2e2f8 commit 9b01af2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BymlLibrary/Byml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ public class ValueEqualityComparer : IEqualityComparer<Byml>
{
private static readonly BymlHashMap32.ValueEqualityComparer _hashMap32Comparer = new();
private static readonly BymlHashMap64.ValueEqualityComparer _hashMap64Comparer = new();
private static readonly BymlArrayChangelog.ValueEqualityComparer _bymlArrayChangelogComparer = new();
private static readonly BymlArray.ValueEqualityComparer _arrayComparer = new();
private static readonly BymlMap.ValueEqualityComparer _mapComparer = new();
private static readonly ValueEqualityComparer _default = new();
Expand All @@ -445,6 +446,7 @@ public bool Equals(Byml? x, Byml? y)
return x.Type switch {
BymlNodeType.HashMap32 => _hashMap32Comparer.Equals(x.GetHashMap32(), y.GetHashMap32()),
BymlNodeType.HashMap64 => _hashMap64Comparer.Equals(x.GetHashMap64(), y.GetHashMap64()),
BymlNodeType.ArrayChangelog => _bymlArrayChangelogComparer.Equals(x.GetArrayChangelog(), y.GetArrayChangelog()),
BymlNodeType.Map => _mapComparer.Equals(x.GetMap(), y.GetMap()),
BymlNodeType.Array => _arrayComparer.Equals(x.GetArray(), y.GetArray()),
BymlNodeType.String => x.Value.GetHashCode() == y.Value.GetHashCode(),
Expand Down
37 changes: 37 additions & 0 deletions src/BymlLibrary/Nodes/Containers/BymlArrayChangelog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BymlLibrary.Extensions;
using BymlLibrary.Nodes.Containers.HashMap;
using BymlLibrary.Writers;
using BymlLibrary.Yaml;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -87,4 +88,40 @@ void IBymlNode.Write(BymlWriter context, Action<Byml> write)

context.Writer.Align(4);
}

public class ValueEqualityComparer : IEqualityComparer<BymlArrayChangelog>
{
public bool Equals(BymlArrayChangelog? x, BymlArrayChangelog? y)
{
if (x is null || y is null) {
return y == x;
}

if (x.Count != y.Count) {
return false;
}

return x.Keys.SequenceEqual(y.Keys) && x.Values.SequenceEqual(y.Values, EntryValueEqualityComparer.Default);
}

public int GetHashCode([DisallowNull] BymlArrayChangelog obj)
{
throw new NotImplementedException();
}
}

private class EntryValueEqualityComparer : IEqualityComparer<(BymlChangeType Change, Byml Node)>
{
public static readonly EntryValueEqualityComparer Default = new();

public bool Equals((BymlChangeType Change, Byml Node) x, (BymlChangeType Change, Byml Node) y)
{
return x.Change == y.Change && Byml.ValueEqualityComparer.Default.Equals(x.Node, y.Node);
}

public int GetHashCode([DisallowNull] (BymlChangeType, Byml) obj)
{
throw new NotImplementedException();
}
}
}

0 comments on commit 9b01af2

Please sign in to comment.