Skip to content

Commit

Permalink
Optimized Equals check
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Oct 13, 2023
1 parent 73ecc14 commit bd3e2f5
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/Pgvector/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,7 @@ public float[] ToArray()
=> Memory.ToArray();

public bool Equals(Vector? other)
{
if (other is null || other.Memory.Length != Memory.Length)
{
return false;
}

var span1 = Memory.Span;
var span2 = other.Memory.Span;

for (var i = 0; i < Memory.Length; i++)
{
if (span1[i] != span2[i])
{
return false;
}
}

return true;
}
=> other is not null && Memory.Span.SequenceEqual(other.Memory.Span);

public override bool Equals(object? obj)
=> obj is Vector vector && Equals(vector);
Expand Down

0 comments on commit bd3e2f5

Please sign in to comment.