@ -1301,28 +1301,65 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Check equality. If this is regular vector, then check by base implementation. If Sparse - use own method .
/// Returns a hash code for this instance .
/// </summary>
/// <param name="obj">Object to compare</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override bool Equals ( object obj )
public override int GetHashCode ( )
{
var sparseVector = obj as SparseVector ;
var hashNum = Math . Min ( NonZerosCount , 2 0 ) ;
long hash = 0 ;
for ( var i = 0 ; i < hashNum ; i + + )
{
#if SILVERLIGHT
hash ^ = Precision . DoubleToInt64Bits ( this . _ nonZeroValues [ i ] . GetHashCode ( ) ) ;
#else
hash ^ = BitConverter . DoubleToInt64Bits ( _ nonZeroValues [ i ] . GetHashCode ( ) ) ;
#endif
}
if ( sparseVector = = null )
return BitConverter . ToInt32 ( BitConverter . GetBytes ( hash ) , 4 ) ;
}
#endregion
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">
/// An object to compare with this object.
/// </param>
/// <returns>
/// <c>true</c> if the current object is equal to the <paramref name="other"/> parameter; otherwise, <c>false</c>.
/// </returns>
public override bool Equals ( Vector < Complex32 > other )
{
// Reject equality when the argument is null or has a different length.
if ( other = = null )
{
return base . Equals ( obj ) ;
return false ;
}
if ( Count ! = other . Count )
{
return false ;
}
// Accept if the argument is the same object as this.
if ( ReferenceEquals ( this , sparseVector ) )
if ( ReferenceEquals ( this , othe r) )
{
return true ;
}
if ( ( Count ! = sparseVector . Count ) | | ( NonZerosCount ! = sparseVector . NonZerosCount ) )
var sparseVector = other as SparseVector ;
if ( sparseVector = = null )
{
return base . Equals ( other ) ;
}
if ( NonZerosCount ! = sparseVector . NonZerosCount )
{
return false ;
}
@ -1339,30 +1376,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return true ;
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode ( )
{
var hashNum = Math . Min ( NonZerosCount , 2 0 ) ;
long hash = 0 ;
for ( var i = 0 ; i < hashNum ; i + + )
{
#if SILVERLIGHT
hash ^ = Precision . DoubleToInt64Bits ( this . _ nonZeroValues [ i ] . GetHashCode ( ) ) ;
#else
hash ^ = BitConverter . DoubleToInt64Bits ( _ nonZeroValues [ i ] . GetHashCode ( ) ) ;
#endif
}
return BitConverter . ToInt32 ( BitConverter . GetBytes ( hash ) , 4 ) ;
}
#endregion
/// <summary>
/// Returns an <see cref="IEnumerator{T}"/> that contains the position and value of the element.
/// </summary>