Equivalent to python's -R option that affects the hash of ints

前端 未结 1 1175
粉色の甜心
粉色の甜心 2021-01-11 12:02

We have a large collection of python code that takes some input and produces some output.

We would like to guarantee that, given the identical input, we produce iden

相关标签:
1条回答
  • 2021-01-11 12:24

    Using PyPy is not the best choice here, given that it always retain the insertion order in its dicts (with a method that makes dicts use less memory). We can of course make it change the order dicts are enumerated, but it defeats the point.

    Instead, I'd suggest to hack at the CPython source code to change the way the hash is used inside dictobject.c. For example, after each hash = PyObject_Hash(key); if (hash == -1) { ..error.. }; you could add hash ^= HASH_TWEAK; and compile different versions of CPython with different values for HASH_TWEAK. (I did such a thing at one point, but I can't find it any more. You need to be a bit careful about where the hash values are the original ones or the modified ones.)

    0 讨论(0)
提交回复
热议问题