Skip to content
Snippets Groups Projects
Commit fa73ddde authored by Liam Healy's avatar Liam Healy
Browse files

Combinations working again with foreign-array

Combinations working again with foreign-array, and improved return
from combination-next and combination-previous.  Return value from
#'success-failure is now T or NIL.
parent db94c217
No related branches found
No related tags found
No related merge requests found
;; Combinations ;; Combinations
;; Liam Healy, Sun Mar 26 2006 - 11:51 ;; Liam Healy, Sun Mar 26 2006 - 11:51
;; Time-stamp: <2010-06-29 08:55:43EDT combination.lisp> ;; Time-stamp: <2010-06-29 19:48:55EDT combination.lisp>
;; ;;
;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy ;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License ;; Distributed under the terms of the GNU General Public License
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
"Initialize the combination c to the lexicographically "Initialize the combination c to the lexicographically
last combination, i.e. (n-k,n-k+1,...,n-1).") last combination, i.e. (n-k,n-k+1,...,n-1).")
#|
(defmfun grid:copy-to-destination ((source combination) (destination combination)) (defmfun grid:copy-to-destination ((source combination) (destination combination))
"gsl_combination_memcpy" "gsl_combination_memcpy"
(((mpointer destination) :pointer) (((mpointer destination) :pointer)
...@@ -107,6 +108,7 @@ ...@@ -107,6 +108,7 @@
:documentation ; FDL :documentation ; FDL
"Copy the elements of the combination source into the "Copy the elements of the combination source into the
combination destination. The two combinations must have the same size.") combination destination. The two combinations must have the same size.")
|#
;;;;**************************************************************************** ;;;;****************************************************************************
;;;; Combination properties ;;;; Combination properties
...@@ -154,28 +156,28 @@ ...@@ -154,28 +156,28 @@
(defmfun combination-next (c) (defmfun combination-next (c)
"gsl_combination_next" (((mpointer c) :pointer)) "gsl_combination_next" (((mpointer c) :pointer))
:c-return :success-failure :c-return (crtn :int)
:inputs (c) :inputs (c)
:outputs (c) :outputs (c)
:return ((when (success-failure crtn) c))
:documentation ; FDL :documentation ; FDL
"Advance the combination c to the next combination "Advance the combination c to the next combination in lexicographic
in lexicographic order and return T and c. If no further order and return c. If no further combinations are available
combinations are available it return NIL and c with it returns NIL. Starting with the first combination and repeatedly
c unmodified. Starting with the first combination and applying this function will iterate through all possible
repeatedly applying this function will iterate through all possible
combinations of a given order.") combinations of a given order.")
(defmfun combination-previous (c) (defmfun combination-previous (c)
"gsl_combination_prev" "gsl_combination_prev"
(((mpointer c) :pointer)) (((mpointer c) :pointer))
:c-return :success-failure :c-return (crtn :int)
:inputs (c) :inputs (c)
:outputs (c) :outputs (c)
:return ((when (success-failure crtn) c))
:documentation ; FDL :documentation ; FDL
"Step backwards from the combination c to the "Step backwards from the combination c to the previous combination
previous combination in lexicographic order, returning in lexicographic order, returning c. If no previous combination is
T and c. If no previous combination is available it returns available it returns NIL with c unmodified.")
NIL and c with c unmodified.")
;;;;**************************************************************************** ;;;;****************************************************************************
;;;; Examples and unit test ;;;; Examples and unit test
...@@ -188,15 +190,15 @@ ...@@ -188,15 +190,15 @@
(size comb)) (size comb))
(let ((comb (make-combination 4 2))) ; init-first, combination-next (let ((comb (make-combination 4 2))) ; init-first, combination-next
(init-first comb) (init-first comb)
(loop collect (copy-seq (cl-array comb)) (loop collect (grid:contents comb)
while (combination-next comb))) while (combination-next comb)))
(let ((comb (make-combination 4 2))) ; init-last, combination-previous (let ((comb (make-combination 4 2))) ; init-last, combination-previous
(init-last comb) (init-last comb)
(loop collect (copy-seq (cl-array comb)) (loop collect (grid:contents comb)
while (combination-previous comb))) while (combination-previous comb)))
(loop for i from 0 to 4 ; combination-next (loop for i from 0 to 4 ; combination-next
append append
(let ((comb (make-combination 4 i))) (let ((comb (make-combination 4 i)))
(init-first comb) (init-first comb)
(loop collect (copy-seq (cl-array comb)) (loop collect (grid:contents comb)
while (combination-next comb))))) while (combination-next comb)))))
;; Definition of GSLL system ;; Definition of GSLL system
;; Liam Healy ;; Liam Healy
;; Time-stamp: <2010-06-28 21:18:11EDT gsll.asd> ;; Time-stamp: <2010-06-29 19:26:27EDT gsll.asd>
;; ;;
;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy ;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License ;; Distributed under the terms of the GNU General Public License
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
;(:file "copy-cl") ;(:file "copy-cl")
(:file "array-tests" :depends-on ("both")) (:file "array-tests" :depends-on ("both"))
(:file "permutation" :depends-on ("foreign-array" "array-structs")) (:file "permutation" :depends-on ("foreign-array" "array-structs"))
;(:file "combination" :depends-on ("foreign-array" "array-structs")) (:file "combination" :depends-on ("foreign-array" "array-structs"))
)) ))
#+(or) #+(or)
(:file "polynomial" :depends-on (init data)) (:file "polynomial" :depends-on (init data))
......
;; Macros to interface GSL functions, including definitions necessary for defmfun. ;; Macros to interface GSL functions, including definitions necessary for defmfun.
;; Liam Healy ;; Liam Healy
;; Time-stamp: <2010-06-27 18:03:21EDT interface.lisp> ;; Time-stamp: <2010-06-29 19:42:14EDT interface.lisp>
;; ;;
;; Copyright 2009 Liam M. Healy ;; Copyright 2009 Liam M. Healy
;; Distributed under the terms of the GNU General Public License ;; Distributed under the terms of the GNU General Public License
...@@ -59,7 +59,8 @@ ...@@ -59,7 +59,8 @@
(defun success-failure (value) (defun success-failure (value)
"If status is either +success+ or +continue+, return T; "If status is either +success+ or +continue+, return T;
otherwise, return NIL." otherwise, return NIL."
(member value (list +success+ +continue+))) (when (member value (list +success+ +continue+))
t))
(defun success-continue (value) (defun success-continue (value)
"If status is +success+, return T, otherwise return NIL." "If status is +success+, return T, otherwise return NIL."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment