avoid allocation

master
Matthew Butterick 7 years ago
parent 8409ba623e
commit be1991b224

@ -11,8 +11,10 @@
(define (max-arg vals) (argmax cdr (hash->list vals))) (define (max-arg vals) (argmax cdr (hash->list vals)))
(define max-seen 0) (define max-seen 0)
(define (set-val! key updater) (define (set-val! key updater)
(hash-update! vals key updater 0) (hash-update! vals key (λ (val)
(set! max-seen (max max-seen (cdr (max-arg vals))))) (define new-val (updater val))
(set! max-seen (max max-seen new-val))
new-val) 0))
(provide >= <= < > ==) (provide >= <= < > ==)
(define-macro-cases cmp (define-macro-cases cmp