Test case and pair of hash functions | Takashi Kato | 04 Feb 2016 13:06 UTC |

Re: Test case and pair of hash functions | taylanbayirli@xxxxxx | 04 Feb 2016 14:12 UTC |

Re: Test case and pair of hash functions | Takashi Kato | 04 Feb 2016 14:20 UTC |

Re: Test case and pair of hash functions | taylanbayirli@xxxxxx | 04 Feb 2016 15:00 UTC |

Re: Test case and pair of hash functions

*taylanbayirli@xxxxxx*04 Feb 2016 14:12 UTCTakashi Kato <ktakashi19@gmail.com> writes: > Hi, > > I'm wondering if the SRFI allow me to merge pair of hash functions into one > procedure. It seems the test case requires to use the car part of the given > pair or using as it is. On hashtable-hash-function's desctiption of Inspection > section describes how it should be. However it's a bit vague to me. Can this > be interpreted like this? > > if pair of (or even list of?) hash functions is given, then implementation > may create a procedure returns an single value of suitable hash. > > Or, it must be either the first element of the pair or whole pair? Quoting the specification of make-hashtable, which is normative: Implementations using a hashing strategy that involves a single hash function should ignore one of the functions in the pair when given a pair of hash functions. That's all; it's unspecified which should be ignored. The relevant test case is: (let ((table (make-hashtable (cons equal-hash equal-hash) equal?))) (let ((hash (hashtable-hash-function table))) (test-assert (or (eq? equal-hash hash) (and (eq? equal-hash (car hash)) (eq? equal-hash (cdr hash))))))) which as you see also allows the function in the cdr being used. Also, the sentence uses "should". That means an implementation may do something else if it has a justification. So you could merge the two functions into a single one. The important thing is that hashtable-hash-function always returns a legitimate hash function, which when passed to make-hashtable, results in an equivalent behaving hashtable as the one from which the hash function was taken. Taylan