cs: more repairs for old vector-based HAMT

Fix `hash-map` and `hash-for-each` for applicable structs.
This commit is contained in:
Matthew Flatt 2020-09-29 09:50:29 -06:00
parent 58deff8b6f
commit c7e6cbc001
2 changed files with 16 additions and 2 deletions

View File

@ -598,6 +598,20 @@
(for/sum ([v (in-hash-values new-ht)]) (for/sum ([v (in-hash-values new-ht)])
v))) v)))
;; ----------------------------------------
;; Make sure hash-table iteration can call an applicable struct
(let ()
(struct proc (f) #:property prop:procedure (struct-field-index f))
(test '(2) hash-map (hash 'one 1) (proc (lambda (k v) (add1 v))))
(test '(2) hash-map (hasheq 'one 1) (proc (lambda (k v) (add1 v))))
(test '(2) hash-map (hasheqv 'one 1) (proc (lambda (k v) (add1 v))))
(test (void) hash-for-each (hash 'one 1) (proc void))
(test (void) hash-for-each (hasheq 'one 1) (proc void))
(test (void) hash-for-each (hasheqv 'one 1) (proc void)))
;; ---------------------------------------- ;; ----------------------------------------
(report-errs) (report-errs)

View File

@ -129,10 +129,10 @@
(hamt-fold h '() (lambda (_ v xs) (cons v xs)))) (hamt-fold h '() (lambda (_ v xs) (cons v xs))))
(define (intmap-for-each h proc) (define (intmap-for-each h proc)
(hamt-fold h (void) (lambda (k v _) (proc k v) (void)))) (hamt-fold h (void) (lambda (k v _) (|#%app| proc k v) (void))))
(define (intmap-map h proc) (define (intmap-map h proc)
(hamt-fold h '() (lambda (k v xs) (cons (proc k v) xs)))) (hamt-fold h '() (lambda (k v xs) (cons (|#%app| proc k v) xs))))
;; generatic iteration by counting ;; generatic iteration by counting
(define (intmap-iterate-first h) (define (intmap-iterate-first h)