Skip to content

Commit

Permalink
Amalgamate.cpp: use FNV64-1A
Browse files Browse the repository at this point in the history
  • Loading branch information
rindeal committed May 19, 2024
1 parent ad5d082 commit 9d4b984
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions Amalgamate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,32 +277,30 @@ class Amalgamator
}

public:
static int64 calculateStreamHashCode (InputStream& in)
static uint64 calculateStreamHashCode(juce::InputStream& in)
{
int64 t = 0;
const uint64_t FNV_prime = 1099511628211u;
uint64_t hash = 14695981039346656037u;

const int bufferSize = 4096;
HeapBlock <uint8> buffer;
buffer.malloc (bufferSize);
const int bufferSize = 4096;
char buffer[bufferSize];

for (;;)
{
const int num = in.read (buffer, bufferSize);

if (num <= 0)
break;

for (int i = 0; i < num; ++i)
t = t * 65599 + buffer[i];
}
while (int bytesRead = in.read(buffer, bufferSize))
{
for (int i = 0; i < bytesRead; ++i)
{
hash ^= static_cast<unsigned char>(buffer[i]);
hash *= FNV_prime;
}
}

return t;
return hash;
}

static int64 calculateFileHashCode (const File& file)
static uint64 calculateFileHashCode (const File& file)
{
std::unique_ptr <FileInputStream> stream (file.createInputStream());
return stream != 0 ? calculateStreamHashCode (*stream) : 0;
return stream != NULL ? calculateStreamHashCode (*stream) : 0;
}

private:
Expand Down

0 comments on commit 9d4b984

Please sign in to comment.