emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

expose XHASH [patch]


From: Paul Pogonyshev
Subject: expose XHASH [patch]
Date: Thu, 31 Mar 2016 21:29:58 +0200

Suppose you need a hash table with the following Lisp structures
as keys:

    (NAME . [VECTOR-OF-ATTRIBUTES])

where NAME is a string.  The structures are supposed to be
compared in a "mixed" way: NAME with 'equal' (or 'string='), but
VECTOR-OF-ATTRIBUTES should be compared with 'eq', i.e. by
identity.

Now, while defining test function for 'define-hash-table-test' is
not a problem, hash is problematic.  While 'sxhash' _will_ work,
it is wasteful, since it computes needless information about
vector contents.  Excluding vector from the hash completely is
also legal, but might considerably worsen hash table performance.

Attached trivial patch just exposes internally used XHASH(),
which fully suits this usecase.  E.g. with it you could

    (defun my-funny-hash (structure)
      (+ (sxhash (car structure)) (* 13 (xhash (cdr structure)))))

Please don't write that the example is stupid, it is just an
example after all.

Paul



* src/fns.c (Fxhash): New function.

* doc/lispref/hash.texi (Defining Hash): Document 'xhash'.

* etc/NEWS: Mention 'xhash'.

Attachment: xhash.diff
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]