5
(defparameter *count-branches-to-memo-table*
8
(defun count-branches-to (x n)
16
(declare (type (simple-array t (*)) ar)
24
((eq (car x) avrc) nil)
27
(t (setf (aref ar cnt) x)
30
(the fixnum (+ 1 cnt)))
32
(setq cnt (the fixnum (+ 2 cnt)))
34
(return-from outer nil))
37
(rplaca (the cons x) avrc)))))
42
(values (if (>= cnt max)
45
(loop for i fixnum below cnt by 2 do
46
(rplaca (the cons (aref ar i))
47
(aref ar (the fixnum (+ i 1)))))))))
50
(when (not *count-branches-to-memo-table*)
51
(setq *count-branches-to-memo-table* (hl-mht)))
52
(b* (((mv ans present)
53
(gethash x *count-branches-to-memo-table*)))
69
(b* ((x (hons-copy x))
80
(count-branches-to1 dx))
81
(mem (if ans (cons t ans) (cons nil n))))
82
(setf (gethash x *count-branches-to-memo-table*) mem)
83
(setf (gethash dx *count-branches-to-memo-table*) mem)
86
;; BOZO really profile this?
88
(mf-note-arity 'count-branches-to 2 1)
90
(profile-fn 'count-branches-to)
93
;; Dirty hack so as to clear the count-branches-to memoize table whenever
94
;; clearing the other memoize tables. BOZO is this something we need to do?
95
(setf (gethash 'count-branches-to *memoize-info-ht*)
96
(change memoize-info-ht-entry
97
(gethash 'count-branches-to *memoize-info-ht*)
98
:tablename '*count-branches-to-memo-table*))