Skip to content

Commit 14e490b

Browse files
committed
Merge pull request #392 from avibryant/expose-murmurhash-seed
hash(s::ByteString, seed::Uint32)
2 parents 653704d + 2d76c20 commit 14e490b

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

j/table.j

+4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ hash(x::Any) = uid(x)
125125
126126
if WORD_SIZE == 64
127127
hash(s::ByteString) = ccall(:memhash, Uint64, (Ptr{Void}, Int), s.data, length(s.data))
128+
hash(s::ByteString, seed::Uint32) = ccall(:memhash_seed, Uint64, (Ptr{Void}, Int, Uint32), s.data, length(s.data), seed)
128129
else
129130
hash(s::ByteString) = ccall(:memhash32, Uint32, (Ptr{Void}, Int), s.data, length(s.data))
131+
hash(s::ByteString, seed::Uint32) = ccall(:memhash32_seed, Uint32, (Ptr{Void}, Int, Uint32), s.data, length(s.data), seed)
130132
end
131133
134+
135+
132136
# hash table
133137
134138
type HashTable{K,V} <: Associative

src/julia.expmap

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
int64hash;
55
int64to32hash;
66
memhash;
7+
memhash_seed;
78
memhash32;
9+
memhash32_seed;
810
jl_hash_symbol;
911
jl_symbol_name;
1012
jl_uid;

src/support/hashing.c

+21
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,31 @@ uint64_t memhash(const char* buf, size_t n)
7474
return out[1];
7575
}
7676

77+
uint64_t memhash_seed(const char* buf, size_t n, uint32_t seed)
78+
{
79+
uint64_t out[2];
80+
81+
// TODO: expose 128-bit hash
82+
#ifdef __LP64__
83+
MurmurHash3_x64_128(buf, n, seed, out);
84+
#else
85+
MurmurHash3_x86_128(buf, n, seed, out);
86+
#endif
87+
return out[1];
88+
}
89+
7790
uint32_t memhash32(const char* buf, size_t n)
7891
{
7992
uint32_t out;
8093

8194
MurmurHash3_x86_32(buf, n, _MHASH_SEED_, &out);
8295
return out;
8396
}
97+
98+
uint32_t memhash32_seed(const char* buf, size_t n, uint32_t seed)
99+
{
100+
uint32_t out;
101+
102+
MurmurHash3_x86_32(buf, n, seed, &out);
103+
return out;
104+
}

src/support/hashing.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DLLEXPORT u_int32_t int64to32hash(u_int64_t key);
1111
#define inthash int32hash
1212
#endif
1313
DLLEXPORT u_int64_t memhash(const char* buf, size_t n);
14+
DLLEXPORT u_int64_t memhash_seed(const char* buf, size_t n, u_int32_t seed);
1415
DLLEXPORT u_int32_t memhash32(const char* buf, size_t n);
15-
16+
DLLEXPORT u_int32_t memhash32_seed(const char* buf, size_t n, u_int32_t seed);
1617
#endif

0 commit comments

Comments
 (0)