1

I want to use the same hash as C++ std::hash in python.

I have found that std::hash uses murmurhash and i have also found several python libraries with that hashing algorithm, but non returns the same value as std::hash.

I am looking for either a python library that returns the same hash or the seed used in std::hash.

  • 6
    From the standard, `std::hash` is implementation-defined, which means that it might be using [MurmurHash](https://en.wikipedia.org/wiki/MurmurHash) in your particular implementation, but it might be something entirely different on another implementation. Your best bet is probably to pick a specific implementation somewhere and use that in both the Python implementation and in the C++ implementation. – Mats Kindahl Mar 04 '20 at 08:09
  • 1
    You could make a small Python extension library that calls `std::hash` for you. – Botje Mar 04 '20 at 08:48
  • Aside: `std::hash` *of what*? It's a class template with specialisations for a number of types. – Caleth Mar 04 '20 at 10:36
  • N.b. "Hash functions are only required to produce the same result for the same input within a single execution of a program; this allows salted hashes that prevent collision denial-of-service attacks." It might not be meaningful to talk about "returns the same hash" if you are in a separate process – Caleth Mar 04 '20 at 10:38

0 Answers0