Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simpler impl for ByteArrayEqualityComparer and remove redundant impl #3562

Merged
35 changes: 35 additions & 0 deletions src/Neo.Extensions/ByteArrayEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// ByteArrayEqualityComparer.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System.Collections.Generic;
using System.IO.Hashing;
using System.Linq;

namespace Neo.Extensions
{
public class ByteArrayEqualityComparer : IEqualityComparer<byte[]>
{
public static readonly ByteArrayEqualityComparer Default = new();

public bool Equals(byte[]? x, byte[]? y)
{
if (ReferenceEquals(x, y)) return true;
if (x is null || y is null || x.Length != y.Length) return false;

return x.SequenceEqual(y);
}
shargon marked this conversation as resolved.
Show resolved Hide resolved

public int GetHashCode(byte[] obj)
{
return (int)XxHash3.HashToUInt64(obj);
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
1 change: 1 addition & 0 deletions src/Neo.Extensions/Neo.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Akka" Version="1.5.26" />
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
58 changes: 0 additions & 58 deletions src/Neo.IO/ByteArrayEqualityComparer.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Neo/IO/Caching/ECPointCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// modifications are permitted.

using Neo.Cryptography.ECC;
using Neo.Extensions;

namespace Neo.IO.Caching
{
Expand Down
1 change: 1 addition & 0 deletions src/Neo/Persistence/MemorySnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Extensions;
using Neo.IO;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down
1 change: 1 addition & 0 deletions src/Neo/Persistence/MemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.Extensions;
using Neo.IO;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/MPTTrie/Cryptography/MPTTrie/Trie.Proof.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.IO;
using Neo.Extensions;
using Neo.Persistence;
using System;
using System.Collections.Generic;
Expand Down
58 changes: 0 additions & 58 deletions src/Plugins/MPTTrie/IO/ByteArrayEqualityComparer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using System;
using System.Linq;

namespace Neo.UnitTests
namespace Neo.Extensions.Tests
{
[TestClass]
public class UT_ByteArrayEqualityComparer
Expand Down
Loading