Skip to content

Commit

Permalink
Update GetHashCode() method of CompressedColumnStorage class.
Browse files Browse the repository at this point in the history
  • Loading branch information
wo80 committed Apr 3, 2024
1 parent ec9493c commit 81cdafc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CSparse/CSparse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<RootNamespace>CSparse</RootNamespace>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/wo80/CSparse.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/wo80/CSparse.NET</RepositoryUrl>
<RepositoryUrl>https://github.com/wo80/CSparse.NET.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>
The major version change is due to the removal of obsolete methods in the Converter class. Visibility of that class was changed from public to internal. In case those obsolete methods were still used, please switch to the static conversion methods provided by the SparseMatrix class.

Other changes in version 4.0.0:

* Addition of helper method Helper.ValidateStorage(...) to validate the structure of a sparse matrix.
* Update to GetHashCode() method of CompressedColumnStorage class.
* Improvements to documentation.
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
22 changes: 8 additions & 14 deletions CSparse/Storage/CompressedColumnStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public abstract void Add(T alpha, T beta, CompressedColumnStorage<T> other,
CompressedColumnStorage<T> result);

/// <summary>
/// Sparse matrix multiplication, C = A*B
/// Sparse matrix multiplication, C = A * B, where A is the current instance.
/// </summary>
/// <param name="other">The sparse matrix multiplied to this instance (from the right).</param>
/// <returns>C = A*B</returns>
Expand Down Expand Up @@ -896,26 +896,20 @@ internal bool Resize(int size)
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// A hash code for the current <see cref="CompressedColumnStorage{T}"/>.
/// </returns>
public override int GetHashCode()
{
var hashNum = Math.Min(this.NonZerosCount, 25);
var hashNum = Math.Min(NonZerosCount, 50);
int hash = 17;
int i, p, k = 0;
unchecked
{
for (i = 0; i < columns; i++)
{
for (p = ColumnPointers[i]; p < ColumnPointers[i + 1]; p++)
{
hash = hash * 31 + Values[p].GetHashCode();
hash = hash * 31 + NonZerosCount;

if (++k > hashNum)
{
return hash;
}
}
for (int i = 0; i < hashNum; i++)
{
hash = hash * 31 + RowIndices[i];
hash = hash * 31 + Values[i].GetHashCode();
}
}
return hash;
Expand Down

0 comments on commit 81cdafc

Please sign in to comment.