Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Add Buffer.Equals #334

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/neo-vm/Types/Buffer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

namespace Neo.VM.Types
Expand All @@ -24,6 +25,25 @@ public Buffer(ReadOnlySpan<byte> data)
if (!data.IsEmpty) data.CopyTo(InnerBuffer);
}


public override bool Equals(StackItem other)
{
if (ReferenceEquals(this, other)) return true;
if (other is Buffer b) return InnerBuffer.SequenceEqual(b.InnerBuffer);
return false;
}

public override int GetHashCode()
{
unchecked
{
int hash = 17;
foreach (byte element in InnerBuffer)
hash = hash * 31 + element;
return hash;
}
}

public override StackItem ConvertTo(StackItemType type)
{
switch (type)
Expand Down