Skip to content

hash(s::ByteString, seed::Uint32) #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2012
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions j/table.j
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ hash(x::Any) = uid(x)

if WORD_SIZE == 64
hash(s::ByteString) = ccall(:memhash, Uint64, (Ptr{Void}, Int), s.data, length(s.data))
hash(s::ByteString, seed::Uint32) = ccall(:memhash_seed, Uint64, (Ptr{Void}, Int, Uint32), s.data, length(s.data), seed)
else
hash(s::ByteString) = ccall(:memhash32, Uint32, (Ptr{Void}, Int), s.data, length(s.data))
hash(s::ByteString, seed::Uint32) = ccall(:memhash32_seed, Uint32, (Ptr{Void}, Int, Uint32), s.data, length(s.data), seed)
end



# hash table

type HashTable{K,V} <: Associative
Expand Down
2 changes: 2 additions & 0 deletions src/julia.expmap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
int64hash;
int64to32hash;
memhash;
memhash_seed;
memhash32;
memhash32_seed;
jl_hash_symbol;
jl_symbol_name;
jl_uid;
Expand Down
21 changes: 21 additions & 0 deletions src/support/hashing.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,31 @@ uint64_t memhash(const char* buf, size_t n)
return out[1];
}

uint64_t memhash_seed(const char* buf, size_t n, uint32_t seed)
{
uint64_t out[2];

// TODO: expose 128-bit hash
#ifdef __LP64__
MurmurHash3_x64_128(buf, n, seed, out);
#else
MurmurHash3_x86_128(buf, n, seed, out);
#endif
return out[1];
}

uint32_t memhash32(const char* buf, size_t n)
{
uint32_t out;

MurmurHash3_x86_32(buf, n, _MHASH_SEED_, &out);
return out;
}

uint32_t memhash32_seed(const char* buf, size_t n, uint32_t seed)
{
uint32_t out;

MurmurHash3_x86_32(buf, n, seed, &out);
return out;
}
3 changes: 2 additions & 1 deletion src/support/hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DLLEXPORT u_int32_t int64to32hash(u_int64_t key);
#define inthash int32hash
#endif
DLLEXPORT u_int64_t memhash(const char* buf, size_t n);
DLLEXPORT u_int64_t memhash_seed(const char* buf, size_t n, u_int32_t seed);
DLLEXPORT u_int32_t memhash32(const char* buf, size_t n);

DLLEXPORT u_int32_t memhash32_seed(const char* buf, size_t n, u_int32_t seed);
#endif