Allowing alist initializers for memoize cache.

This commit is contained in:
Alex Shinn 2013-12-14 00:03:12 +09:00
parent badc6765f0
commit 0e7baa96e8

View file

@ -93,14 +93,22 @@
(init-size init-size: 31) (init-size init-size: 31)
(limit size-limit: 1000) (limit size-limit: 1000)
(compute-size compute-size: (lambda (k v) 1)) (compute-size compute-size: (lambda (k v) 1))
(cache cache: (if limit (cache-init cache: '()))
(let ((cache (cond ((lru-cache? cache-init)
cache-init)
(limit
(make-lru-cache 'equal: equal (make-lru-cache 'equal: equal
'hash: hash 'hash: hash
'init-size: init-size 'init-size: init-size
'size-limit: limit 'size-limit: limit
'compute-size: compute-size) 'compute-size: compute-size))
(make-hash-table equal hash)))) (else
(make-memoizer proc arity cache))) (make-hash-table equal hash)))))
;; allow an alist initializer for the cache
(if (pair? cache-init)
(for-each (lambda (x) (lru-add! cache (car x) (cdr x)))
cache-init))
(make-memoizer proc arity cache))))
;;> Equivalent to memoize except that the procedure's first argument ;;> Equivalent to memoize except that the procedure's first argument
;;> must be a pathname. If the corresponding file has been modified ;;> must be a pathname. If the corresponding file has been modified