diff options
author | Thomas Bushnell, BSG <tb@debian.org> | 2005-11-02 14:55:21 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:32 -0800 |
commit | 34c54a22ff7818bb8b38ef4d9c87dbbcb221ba73 (patch) | |
tree | 1189d06a81277bcf8539b0260a69a19f6038effb /dbinterp.scm | |
parent | 611b3db17894e5fdc0db3d49eaf6743d27b44233 (diff) | |
parent | 5145dd3aa0c02c9fc496d1432fc4410674206e1d (diff) | |
download | slib-34c54a22ff7818bb8b38ef4d9c87dbbcb221ba73.tar.gz slib-34c54a22ff7818bb8b38ef4d9c87dbbcb221ba73.zip |
Import Debian changes 3a2-1debian/3a2-1
slib (3a2-1) unstable; urgency=low
* New upstream release.
* Acknowledge NMU. (Closes: #281809)
* Makefile: Don't hack Makefile; use rules instead.
* debian/rules: Set on make invocations: prefix, htmldir, TEXI2HTML.
* debian/rules (clean): Clean more stuff here.
* Makefile: Comment out old rule for $(htmldir)slib_toc.html. Instead,
specify directly that the texi2html invocation produces that file.
* debian/rules (binary-indep): Find web files in slib subdir.
* debian/control (Build-Depends-Indep): Go back to using scm.
Diffstat (limited to 'dbinterp.scm')
-rw-r--r-- | dbinterp.scm | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/dbinterp.scm b/dbinterp.scm index 8ccb1df..2bd4e20 100644 --- a/dbinterp.scm +++ b/dbinterp.scm @@ -17,18 +17,36 @@ ;promotional, or sales literature without prior written consent in ;each case. +(require 'rev4-optional-procedures) ; list-tail + +;;; The procedures returned by MEMOIZE are not reentrant! +(define (dbinterp:memoize proc k) + (define recent (vector->list (make-vector k '(#f)))) + (let ((tailr (list-tail recent (+ -1 k)))) + (lambda args + (define asp (assoc args recent)) + (if asp + (cdr asp) + (let ((val (apply proc args))) + (set-cdr! tailr (list (cons args val))) + (set! tailr (cdr tailr)) + (set! recent (cdr recent)) + val))))) + ;;@ This procedure works only for tables with a single primary key. (define (interpolate-from-table table column) - (define get (table 'get column)) - (define prev (table 'isam-prev)) + (define get (dbinterp:memoize (table 'get column) 3)) + (define prev (dbinterp:memoize (table 'isam-prev) 3)) (define next (table 'isam-next)) - (lambda (x) - (let ((nxt (next x))) - (if nxt (set! nxt (car nxt))) - (let ((prv (prev (or nxt x)))) - (if prv (set! prv (car prv))) - (cond ((not nxt) (get prv)) - ((not prv) (get nxt)) - (else (/ (+ (* (- x prv) (get nxt)) - (* (- nxt x) (get prv))) - (- nxt prv)))))))) + (dbinterp:memoize + (lambda (x) + (let ((nxt (next x))) + (if nxt (set! nxt (car nxt))) + (let ((prv (prev (or nxt x)))) + (if prv (set! prv (car prv))) + (cond ((not nxt) (get prv)) + ((not prv) (get nxt)) + (else (/ (+ (* (- x prv) (get nxt)) + (* (- nxt x) (get prv))) + (- nxt prv))))))) + 3)) |