[Openmcl-devel] hash-table-hash-function

Gary Byers gb at clozure.com
Tue Apr 21 13:13:17 PDT 2009



On Tue, 21 Apr 2009, Chris Dean wrote:

>
> [Looks like my earlier message was scrubbed, so I'll repost.]

It wasn't lost, but sometimes it takes a few days to think of
a reply.

>
> Is there an existing way to extract the hash-function from a hash-table?

No, and there isn't even something that behaves strictly as a 
hash function (in the sense that SXHASH is a hash function.)  The
functions that're explicitly or otherwise referenced form the
nhash.keytransF slot are concerned not only with transforming
the key into an integer but with determining whether the address
of the key or any of its components factors into hashing.  The
primary user of nhash.keytransF - an inlined function named
COMPUTE-HASH-CODE - sometimes scrambles some bits in the primary
return value before actually using them, and sometimes sets some
bits in the hash table to advise the GC that its cooperation may
be needed to identify cases where changes in object addresses
require rehashing.

These aren't exactly intended to be user-callable hashing functions
in the sense that SXHASH is; if someone says that they need to
get their hands on these functions, my first reaction is skepticism.


> Turns out that I need one to properly serialize some data structures.
>
> In case there isn't one, I have a patch below to add a
> hash-table-hash-function and put it in the CCL package.
>
> Cheers,
> Chris Dean
>
>
> Index: lib/ccl-export-syms.lisp
> ===================================================================
> --- lib/ccl-export-syms.lisp	(revision 11952)
> +++ lib/ccl-export-syms.lisp	(working copy)
> @@ -271,6 +271,8 @@
>      init-list-default
>      fset
>
> +     hash-table-hash-function
> +
> 					; Files.
>      mac-default-directory
>      current-directory
> Index: level-0/l0-hash.lisp
> ===================================================================
> --- level-0/l0-hash.lisp	(revision 11952)
> +++ level-0/l0-hash.lisp	(working copy)
> @@ -576,6 +576,13 @@
>       (if (eql 0 f) #'eq #'eql)
>       f)))
>
> +(defun hash-table-hash-function (hash)
> +  "Return the hashing function HASH-TABLE was created with."
> +  (let ((fn (nhash.keytransF (require-type hash 'hash-table))))
> +    (if (fixnump fn)
> +        nil
> +        fn)))
> +
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;
> ;; nearly-lock-free hash tables
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list