Skip to content

Commit

Permalink
Change uses of int to size_t in MurmurHash (#48562)
Browse files Browse the repository at this point in the history
* Change uses of int to size_t in MurmurHash
  • Loading branch information
gbaraldi authored Feb 7, 2023
1 parent 8860d95 commit 3fe69f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/support/MurmurHash3.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ FORCE_INLINE uint64_t fmix64 ( uint64_t k )

//-----------------------------------------------------------------------------

void MurmurHash3_x86_32 ( const void * key, int len,
void MurmurHash3_x86_32 ( const void * key, size_t len,
uint32_t seed, void * out )
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 4;
const size_t nblocks = len / 4;

uint32_t h1 = seed;

Expand All @@ -73,7 +73,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,

const uint8_t * tail = data + nblocks*4;

for(int i = -nblocks; i; i++)
for(size_t i = -nblocks; i; i++)
{
uint32_t k1 = jl_load_unaligned_i32(tail + sizeof(uint32_t)*i);

Expand Down Expand Up @@ -111,11 +111,11 @@ void MurmurHash3_x86_32 ( const void * key, int len,

//-----------------------------------------------------------------------------

void MurmurHash3_x86_128 ( const void * key, const int len,
void MurmurHash3_x86_128 ( const void * key, const size_t len,
uint32_t seed, void * out )
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 16;
const size_t nblocks = len / 16;

uint32_t h1 = seed;
uint32_t h2 = seed;
Expand All @@ -132,7 +132,7 @@ void MurmurHash3_x86_128 ( const void * key, const int len,

const uint8_t *tail = data + nblocks*16;

for(int i = -nblocks; i; i++)
for(size_t i = -nblocks; i; i++)
{
uint32_t k1 = jl_load_unaligned_i32(tail + sizeof(uint32_t)*(i*4 + 0));
uint32_t k2 = jl_load_unaligned_i32(tail + sizeof(uint32_t)*(i*4 + 1));
Expand Down Expand Up @@ -217,11 +217,11 @@ void MurmurHash3_x86_128 ( const void * key, const int len,

//-----------------------------------------------------------------------------

void MurmurHash3_x64_128 ( const void * key, const int len,
void MurmurHash3_x64_128 ( const void * key, const size_t len,
const uint32_t seed, void * out )
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 16;
const size_t nblocks = len / 16;

uint64_t h1 = seed;
uint64_t h2 = seed;
Expand All @@ -232,7 +232,7 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
//----------
// body

for(int i = 0; i < nblocks; i++)
for(size_t i = 0; i < nblocks; i++)
{
uint64_t k1 = jl_load_unaligned_i64(data + sizeof(uint64_t)*(i*2 + 0));
uint64_t k2 = jl_load_unaligned_i64(data + sizeof(uint64_t)*(i*2 + 1));
Expand Down
8 changes: 4 additions & 4 deletions src/support/MurmurHash3.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
//-----------------------------------------------------------------------------
// Platform-specific functions and macros
#include <stdint.h>

#include <stddef.h>
//-----------------------------------------------------------------------------

void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
void MurmurHash3_x86_32 ( const void * key, size_t len, uint32_t seed, void * out );

void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out );
void MurmurHash3_x86_128 ( const void * key, size_t len, uint32_t seed, void * out );

void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out );
void MurmurHash3_x64_128 ( const void * key, size_t len, uint32_t seed, void * out );

//-----------------------------------------------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions test/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,11 @@ end
end
end
end

if Sys.WORD_SIZE >= 64
@testset "very large string" begin
N = 2^31+1
s = String('\0'^N);
objectid(s)
end
end

0 comments on commit 3fe69f4

Please sign in to comment.