ERL_NIF_TERM erlang_murmurhash2_1_impl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary bin; uint32_t h; if (!check_and_unpack_data(env, argv[0], &bin)) { return enif_make_badarg(env); } h = MurmurHash2(bin.data, bin.size, 0); return enif_make_uint(env, h); }
ERL_NIF_TERM erlang_murmurhash3_x86_32_2_impl(ErlNifEnv* env, int, const ERL_NIF_TERM argv[]) { ErlNifBinary bin; uint32_t h; uint32_t seed; if (!check_and_unpack_data(env, argv[0], &bin)) { return enif_make_badarg(env); } if (!enif_get_uint(env, argv[1], &seed)) { return enif_make_badarg(env); } MurmurHash3_x86_32(bin.data, bin.size, seed, &h); return enif_make_uint(env, h); }
ERL_NIF_TERM murmurhash_x86_32_impl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary binary; uint32_t hash; uint32_t seed; // check for valid key arg if( !check_and_unpack_data(env, argv[0], &binary) ) { return enif_make_badarg(env); } // check for valid seed arg if( !enif_get_uint(env, argv[1], &seed) ) { return enif_make_badarg(env); } MurmurHash3_x86_32(binary.data, binary.size, seed, &hash); return enif_make_uint(env, hash); }
ERL_NIF_TERM erlang_murmurhash64b_2_impl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary bin; uint64_t h; uint64_t seed; if (!check_and_unpack_data(env, argv[0], &bin)) { return enif_make_badarg(env); } if (!enif_get_uint64(env, argv[1], &seed)) { return enif_make_badarg(env); } h = MurmurHash64B(bin.data, bin.size, seed); return enif_make_uint64(env, h); }
ERL_NIF_TERM murmurhash_x64_128_impl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary binary; uint64_t hash[2]; uint32_t seed; ERL_NIF_TERM parts[2]; // check for valid key arg if( !check_and_unpack_data(env, argv[0], &binary) ) { return enif_make_badarg(env); } // check for valid seed arg if( !enif_get_uint(env, argv[1], &seed) ) { return enif_make_badarg(env); } MurmurHash3_x64_128(binary.data, binary.size, seed, &hash); parts[0] = hash[0]; parts[1] = hash[1]; return enif_make_list_from_array(env, parts, 2); }
ERL_NIF_TERM murmurhash_x86_128_impl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary binary; uint32_t hash[4] = { 0, 0, 0, 0 }; uint32_t seed; ERL_NIF_TERM parts[4]; // check for valid key arg if( !check_and_unpack_data(env, argv[0], &binary) ) { return enif_make_badarg(env); } // check for valid seed arg if( !enif_get_uint(env, argv[1], &seed) ) { return enif_make_badarg(env); } MurmurHash3_x86_128(binary.data, binary.size, seed, &hash); for( int i = 0; i < 4; i++ ) { parts[i] = enif_make_uint(env, hash[i]); } return enif_make_list_from_array(env, parts, 4); }