Skip to content

Commit

Permalink
pythongh-111389: Make PyHASH_MULTIPLIER constant public
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed May 20, 2024
1 parent 72d07dd commit cd662fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Doc/c-api/hash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.

.. versionadded:: 3.13

.. c:macro:: PyHASH_MULTIPLIER
Prime multiplier used in string and various other hashes.

.. versionadded:: 3.13

.. c:macro:: PyHASH_INF
The hash value returned for a positive infinity.
Expand Down
5 changes: 3 additions & 2 deletions Include/cpython/pyhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#endif

/* Prime multiplier used in string and various other hashes. */
#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */
#define PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */

/* Parameters used for the numeric hash implementation. See notes for
_Py_HashDouble in Python/pyhash.c. Numeric hashes are based on
Expand All @@ -17,9 +17,10 @@

#define PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
#define PyHASH_INF 314159
#define PyHASH_IMAG _PyHASH_MULTIPLIER
#define PyHASH_IMAG PyHASH_MULTIPLIER

/* Aliases kept for backward compatibility with Python 3.12 */
#define _PyHASH_MULTIPLIER PyHASH_MULTIPLIER
#define _PyHASH_BITS PyHASH_BITS
#define _PyHASH_MODULUS PyHASH_MODULUS
#define _PyHASH_INF PyHASH_INF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :c:macro:`PyHASH_MULTIPLIER` constant: prime multiplier used in string
and various other hashes. Patch by Victor Stinner.

0 comments on commit cd662fb

Please sign in to comment.