Fix argument passing for external hash functions in `(rnrs hashtables)'.
Guile implements this library in terms of SRFI-69, which is a bit vague on the arity of hash functions, whereas `(rnrs hashtables)' explicitly specifies unary ones. * module/rnrs/hashtables.scm (wrap-hash-function): Assume SRFI-69 will pass the table capacity as the second argument; return the result of proc modulo the capacity. * test-suite/tests/r6rs-hashtables.test (make-hashtable): New test case for hash functions that return large values.
This commit is contained in:
parent
5b69315ed3
commit
3fdc1d05ae
2 changed files with 11 additions and 3 deletions
|
|
@ -45,7 +45,8 @@
|
|||
(import (rename (only (guile) string-hash-ci
|
||||
string-hash
|
||||
hashq
|
||||
hashv
|
||||
hashv
|
||||
modulo
|
||||
*unspecified*
|
||||
@@)
|
||||
(string-hash-ci string-ci-hash))
|
||||
|
|
@ -88,7 +89,8 @@
|
|||
(define hashtable-mutable? r6rs:hashtable-mutable?)
|
||||
|
||||
(define hash-by-value ((@@ (srfi srfi-69) caller-with-default-size) hashv))
|
||||
(define (wrap-hash-function proc) (lambda (key obj) (proc key)))
|
||||
(define (wrap-hash-function proc)
|
||||
(lambda (key capacity) (modulo (proc key) capacity)))
|
||||
|
||||
(define* (make-eq-hashtable #:optional k)
|
||||
(make-r6rs-hashtable
|
||||
|
|
|
|||
|
|
@ -45,7 +45,13 @@
|
|||
(abs-hashtable (make-hashtable abs abs-eqv?)))
|
||||
(hashtable-set! abs-hashtable -4 #t)
|
||||
(and (not (hashtable-contains? abs-hashtable 6))
|
||||
(hashtable-contains? abs-hashtable 4)))))
|
||||
(hashtable-contains? abs-hashtable 4))))
|
||||
|
||||
(pass-if "hash function value used modulo capacity"
|
||||
(let* ((constant-hash (lambda (x) most-positive-fixnum))
|
||||
(constant-hashtable (make-hashtable constant-hash eq?)))
|
||||
(hashtable-set! constant-hashtable 'foo 'bar)
|
||||
(hashtable-contains? constant-hashtable 'foo))))
|
||||
|
||||
(with-test-prefix "hashtable?"
|
||||
(pass-if "hashtable? is #t on hashtables"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue