more hash functions

This commit is contained in:
Sam Caldwell 2019-05-15 17:25:11 -04:00
parent 1590687e7a
commit 5310956848
2 changed files with 15 additions and 7 deletions

View File

@ -127,10 +127,10 @@ The JobManager then performs the job and, when finished, asserts (job-finished I
(define (word-count-increment [h : WordCount] (define (word-count-increment [h : WordCount]
[word : String] [word : String]
-> WordCount) -> WordCount)
(hash-update h (hash-update/failure h
word word
add1 add1
#;(λ x 0))) (lambda () 0)))
(define (count-new-words [word-count : WordCount] (define (count-new-words [word-count : WordCount]
[words : (List String)] [words : (List String)]
@ -168,9 +168,7 @@ The JobManager then performs the job and, when finished, asserts (job-finished I
(define wc (count-new-words (ann (hash) WordCount) (string->words data))) (define wc (count-new-words (ann (hash) WordCount) (string->words data)))
(set! state (finished wc))] (set! state (finished wc))]
[(reduce-work (bind left WordCount) (bind right WordCount)) [(reduce-work (bind left WordCount) (bind right WordCount))
;; TODO - this kind of hash-union (define wc (hash-union/combine left right +))
#;(define wc (hash-union left right #:combine +))
(define wc left)
(set! state (finished wc))]) (set! state (finished wc))])
(set! status IDLE)] (set! status IDLE)]
[#t [#t

View File

@ -7,6 +7,8 @@
hash-ref hash-ref
hash-has-key? hash-has-key?
hash-update hash-update
(typed-out [[hash-update/failure- : ( (K V) (→fn (Hash K V) K (→fn V V) (→fn V) (Hash K V)))]
hash-update/failure])
hash-remove hash-remove
hash-map hash-map
hash-keys hash-keys
@ -15,6 +17,8 @@
hash-count hash-count
hash-empty? hash-empty?
hash-union hash-union
(typed-out [[hash-union/combine- : ( (K V) (→fn (Hash K V) (Hash K V) (→fn V V V) (Hash K V)))]
hash-union/combine])
) )
(require "core-types.rkt") (require "core-types.rkt")
@ -67,3 +71,9 @@
[hash-union : ( (K1 V1 K2 V2) (→fn (Hash K1 V1) (Hash K2 V2) (Hash (U K1 K2) (U V1 V2))))] [hash-union : ( (K1 V1 K2 V2) (→fn (Hash K1 V1) (Hash K2 V2) (Hash (U K1 K2) (U V1 V2))))]
;; TODO - hash-union with #:combine ;; TODO - hash-union with #:combine
) )
(define- (hash-update/failure- h k u err)
(#%app- hash-update- h k u err))
(define- (hash-union/combine- h1 h2 combine)
(#%app- hash-union- h1 h2 #:combine combine))