From f240fcde85cf490ca9460683e4f8ad7dabb9ea10 Mon Sep 17 00:00:00 2001 From: Utz-Uwe Haus Date: Tue, 22 Jun 2010 22:42:48 +0200 Subject: [PATCH] Reduce consing and recursion in split-delimited-string ACL did not recognize tail-recursion Signed-off-by: Utz-Uwe Haus --- dimacs.lisp | 13 +++++++------ satwrap.lisp | 9 --------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/dimacs.lisp b/dimacs.lisp index 0073690..c408ee2 100644 --- a/dimacs.lisp +++ b/dimacs.lisp @@ -36,12 +36,13 @@ "Return a list of the substrings of STRING that are separated by CHAR. Without CHAR." (declare (type string string) (type character char)) - (let ((next-separator (position char string :test #'char=))) - (if next-separator - (cons (subseq string 0 next-separator) - (split-delimited-string (subseq string (1+ next-separator)) - char)) - `(,string)))) + (let ((res '())) + (loop :as last-pos := 0 :then (1+ next-pos) + :as next-pos := (position char string :start last-pos :test #'char=) + :while next-pos + :do (push (subseq string last-pos next-pos) res) + :finally (push (subseq string last-pos) res)) + (nreverse res))) (defgeneric read-dimacs (solver source) (:documentation "Read DIMACS-style sat problem from SOURCE into SOLVER.") diff --git a/satwrap.lisp b/satwrap.lisp index 9bd436c..116b7b2 100644 --- a/satwrap.lisp +++ b/satwrap.lisp @@ -84,15 +84,6 @@ :always (and (not (zerop v)) (<= min v max)))) -(defmethod clause-valid ((solver sat-solver) (clause vector)) - "Check that CLAUSE is a valid clause for SOLVER." - (loop - :with max := (sat-solver-numvars solver) - :with min := (- max) - :for v :across clause - :always (and (not (zerop v)) - (<= min v max)))) - (defmacro iota (n &optional (start 1)) "Return a list of the N sequential integers starting at START (default: 1)." (let ((i (gensym "i"))) -- 2.11.4.GIT