|
From: | Philippe Schnoebelen |
Subject: | What's the specification for sxhash? |
Date: | Thu, 6 Jun 2019 09:55:00 +0200 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 |
Some of my elisp code broke down when I ran it on a newer emacs because the values returned by sxhash are different from what they were in the old version. I had assumed without thinking that sxhash'es of Lisp objects
were fixed one and for all, a bit like the shasum of some file. Probably the doc string should be more explicit about what is/is not guaranteed. Is consistency only guaranteed inside the current running emacs thread/process?
Looking at the source code in src/fns.c, it seems that the change of sxhash values was caused by the recent change allowing emacs lisp integers of arbitrary size. These numbers are hashed differently, and hashing itself has to truncate large integers that are now a different data type. (However, I have also found changes in sxhash values between v26.1 and v26.2, before the move to arbitrary large integers in v27, see examples below.) Looking at the source code, one would think that sxhash values
are meant to only depend on the structure of the Lisp object
itself, not the hardware or the emacs version, but of course this
view may have to yield when the C data type for Lisp objects is
modified. Is this what the developers had in mind?
Today the elisp manual reads — Function: sxhash-equal obj
This does not address the consistency issue, and is a bit misleading about collisions with its "once in a rare while, by luck". Without trying, I stumbled upon many collisions in my test. Is sxhash really intended to avoid collisions? Many thanks for your time, --philippe
Here is what I obtained by running emacs -Q --batch -l
sxhash-report.el (.el file attached below) on 3 different versions
of emacs: in GNU Emacs 26.1 (build 1, x86_64-apple-darwin18.6.0, NS
appkit-1671.50 Version 10.14.5 (Build 18F132)) in GNU Emacs 26.2 (build 1, x86_64-apple-darwin18.2.0, NS
appkit-1671.20 Version 10.14.3 (Build 18D109)) in GNU Emacs 27.0.50 (build 1, x86_64-apple-darwin18.6.0, NS
appkit-1671.50 Version 10.14.5 (Build 18F132))
|
sxhash-report.el
Description: Text document
[Prev in Thread] | Current Thread | [Next in Thread] |