Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Allow LogData to be called in multi threaded environment #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/HyperLogLog.net/HyperLogLog.net/HyperLogLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class HyperLogLog
internal readonly byte[] _registers;
private readonly HashAlgorithm _hashAlgorithm;
private readonly IBytesConverter _bytesConverter;
private readonly object _hashLock = new object();

#region Constants

Expand Down Expand Up @@ -108,7 +109,12 @@ private double FastPow2(int x)
private ulong GetHash(object data)
{
var dataBytes = _bytesConverter.GetBytes(data);
var hashBytes = _hashAlgorithm.ComputeHash(dataBytes);
var hashBytes = new byte[0];

lock (_hashLock)
{
hashBytes = _hashAlgorithm.ComputeHash(dataBytes);
}

// XORing the hash into 64bits sections is not required - we can just take the first 64 bits
//ulong hash = 0;
Expand Down