8000 gh-111545: Add Py_HashDouble() function by vstinner · Pull Request #112449 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111545: Add Py_HashDouble() function #112449

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update
  • Loading branch information
vstinner committed Dec 12, 2023
commit dd19138a11852a824206848b2a4bca744ef76904
7 changes: 3 additions & 4 deletions Doc/c-api/hash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ Functions

Hash a C double number.

* Set *\*result* to the hash and return ``1`` if *value* is finite or is
infinity.
* Set *\*result* to :data:`sys.hash_info.nan <sys.hash_info>` (``0``) and
return ``0`` if *value* is not-a-number (NaN).
* Set *\*result* to the hash value and return ``1`` on success.
* Set *\*result* to ``0`` and return ``0`` if the hash value cannot be
calculated. For example, if value is not-a-number (NaN).

*result* must not be ``NULL``.

Expand Down
8 changes: 1 addition & 7 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,7 @@ always available.

.. attribute:: hash_info.nan

The hash value returned for not-a-number (NaN).

This hash value is only used by the :c:func:`Py_HashDouble` C function if
the argument is not-a-number (NaN).

.. versionchanged:: 3.10
This hash value is no longer used to hash numbers in Python.
(This attribute is no longer used)

.. attribute:: hash_info.imag

Expand Down
1 change: 0 additions & 1 deletion Include/cpython/pyhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
#define _PyHASH_INF 314159
#define _PyHASH_NAN 0
#define _PyHASH_IMAG _PyHASH_MULTIPLIER

/* Helpers for hash functions */
Expand Down
2 changes: 1 addition & 1 deletion Python/pyhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Py_HashDouble(double v, Py_hash_t *result)
}
else {
assert(Py_IS_NAN(v));
*result = _PyHASH_NAN;
*result = 0;
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ get_hash_info(PyThreadState *tstate)
PyStructSequence_SET_ITEM(hash_info, field++,
PyLong_FromLong(_PyHASH_INF));
PyStructSequence_SET_ITEM(hash_info, field++,
PyLong_FromLong(_PyHASH_NAN));
PyLong_FromLong(0)); // This is no longer used
PyStructSequence_SET_ITEM(hash_info, field++,
PyLong_FromLong(_PyHASH_IMAG));
PyStructSequence_SET_ITEM(hash_info, field++,
Expand Down
0