Skip to content

Commit 81cdafc

Browse files
committed
Update GetHashCode() method of CompressedColumnStorage class.
1 parent ec9493c commit 81cdafc

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

CSparse/CSparse.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
<RootNamespace>CSparse</RootNamespace>
2020
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
2121
<PackageProjectUrl>https://github.com/wo80/CSparse.NET</PackageProjectUrl>
22-
<RepositoryUrl>https://github.com/wo80/CSparse.NET</RepositoryUrl>
22+
<RepositoryUrl>https://github.com/wo80/CSparse.NET.git</RepositoryUrl>
2323
<RepositoryType>git</RepositoryType>
2424
<PackageReleaseNotes>
2525
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.
2626

2727
Other changes in version 4.0.0:
2828

2929
* Addition of helper method Helper.ValidateStorage(...) to validate the structure of a sparse matrix.
30+
* Update to GetHashCode() method of CompressedColumnStorage class.
3031
* Improvements to documentation.
3132
</PackageReleaseNotes>
3233
</PropertyGroup>

CSparse/Storage/CompressedColumnStorage.cs

+8-14
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public abstract void Add(T alpha, T beta, CompressedColumnStorage<T> other,
471471
CompressedColumnStorage<T> result);
472472

473473
/// <summary>
474-
/// Sparse matrix multiplication, C = A*B
474+
/// Sparse matrix multiplication, C = A * B, where A is the current instance.
475475
/// </summary>
476476
/// <param name="other">The sparse matrix multiplied to this instance (from the right).</param>
477477
/// <returns>C = A*B</returns>
@@ -896,26 +896,20 @@ internal bool Resize(int size)
896896
/// Serves as a hash function for a particular type.
897897
/// </summary>
898898
/// <returns>
899-
/// A hash code for the current <see cref="T:System.Object"/>.
899+
/// A hash code for the current <see cref="CompressedColumnStorage{T}"/>.
900900
/// </returns>
901901
public override int GetHashCode()
902902
{
903-
var hashNum = Math.Min(this.NonZerosCount, 25);
903+
var hashNum = Math.Min(NonZerosCount, 50);
904904
int hash = 17;
905-
int i, p, k = 0;
906905
unchecked
907906
{
908-
for (i = 0; i < columns; i++)
909-
{
910-
for (p = ColumnPointers[i]; p < ColumnPointers[i + 1]; p++)
911-
{
912-
hash = hash * 31 + Values[p].GetHashCode();
907+
hash = hash * 31 + NonZerosCount;
913908

914-
if (++k > hashNum)
915-
{
916-
return hash;
917-
}
918-
}
909+
for (int i = 0; i < hashNum; i++)
910+
{
911+
hash = hash * 31 + RowIndices[i];
912+
hash = hash * 31 + Values[i].GetHashCode();
919913
}
920914
}
921915
return hash;

0 commit comments

Comments
 (0)