Skip to content
Snippets Groups Projects
lookup.lisp 2.18 KiB
Newer Older
liam's avatar
liam committed
;; Index lookup and acceleration
;; Liam Healy, Sun Nov  4 2007 - 18:09
Liam M. Healy's avatar
Liam M. Healy committed
;; Time-stamp: <2011-01-10 10:29:57EST lookup.lisp>
Liam M. Healy's avatar
Liam M. Healy committed
;; Copyright 2007, 2008, 2009, 2011 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
Liam M. Healy's avatar
Liam M. Healy committed
;;; antik:acceleration refers to the time derivative of velocity but
;;; there's no conflict here with the object 'gsl:acceleration, so we
;;; shadow import the symbol from antik.
(shadowing-import 'antik:acceleration)

(defmobject acceleration "gsl_interp_accel"
  ()
  "acceleration for interpolation"
  :documentation			; FDL
  "Make an accelerator object, which is a
   kind of iterator for interpolation lookups.  It tracks the state of
   lookups, thus allowing for application of various acceleration
   strategies.")

liam's avatar
liam committed
(defmfun interpolation-search (x-array x low-index high-index)
Liam Healy's avatar
Liam Healy committed
  ((x-array :pointer) (x :double) (low-index sizet) (high-index sizet))
  :c-return sizet
liam's avatar
liam committed
  :documentation			; FDL
  "Find the index i of the array x-array such
   that x-array[i] <= x < x-array[i+1].  The index is searched for
   in the range [low-index, high-index].")

liam's avatar
liam committed
(defmfun accelerated-interpolation-search (x-array x acceleration)
  (((mpointer acceleration) :pointer) (x-array :pointer) (x :double))
Liam Healy's avatar
Liam Healy committed
  :c-return sizet
liam's avatar
liam committed
  :documentation			; FDL
  "Search the data array x-array of size, using the given acceleration.
   This is how lookups are performed during evaluation of an interpolation.  The
   function returns an index i such that x_array[i] <= x < x_array[i+1]}.")