[gsharp-cvs] CVS update: gsharp/Flexichain/flexichain-package.lisp gsharp/Flexichain/flexirank.lisp

Robert Strandh rstrandh at common-lisp.net
Mon Nov 28 21:27:05 UTC 2005


Update of /project/gsharp/cvsroot/gsharp/Flexichain
In directory common-lisp.net:/tmp/cvs-serv31819

Modified Files:
	flexichain-package.lisp flexirank.lisp 
Log Message:
added flexi-first-p and flexi-last-p to flexirank.lisp

Date: Mon Nov 28 22:27:03 2005
Author: rstrandh

Index: gsharp/Flexichain/flexichain-package.lisp
diff -u gsharp/Flexichain/flexichain-package.lisp:1.5 gsharp/Flexichain/flexichain-package.lisp:1.6
--- gsharp/Flexichain/flexichain-package.lisp:1.5	Mon Nov 28 00:43:50 2005
+++ gsharp/Flexichain/flexichain-package.lisp	Mon Nov 28 22:27:02 2005
@@ -38,5 +38,6 @@
 	   #:insert #:insert-sequence
 	   #:element< #:element> #:delete< #:delete>
 	   #:flexirank-mixin #:element-rank-mixin #:rank
+	   #:flexi-first-p #:flexi-last-p
 	   #:flexi-next #:flexi-prev))
 


Index: gsharp/Flexichain/flexirank.lisp
diff -u gsharp/Flexichain/flexirank.lisp:1.3 gsharp/Flexichain/flexirank.lisp:1.4
--- gsharp/Flexichain/flexirank.lisp:1.3	Mon Nov 28 01:25:59 2005
+++ gsharp/Flexichain/flexirank.lisp	Mon Nov 28 22:27:02 2005
@@ -28,6 +28,8 @@
 ;;; generic function rank.
 
 (defgeneric rank (element))
+(defgeneric flexi-first-p (element))
+(defgeneric flexi-last-p (element))
 (defgeneric flexi-next (element))
 (defgeneric flexi-prev (element))
 
@@ -38,16 +40,19 @@
 (defmethod rank ((element element-rank-mixin))
   (index-position (chain element) (index element)))
 
+(defmethod flexi-first-p ((element element-rank-mixin))
+  (zerop (rank element)))
+
+(defmethod flexi-last-p ((element element-rank-mixin))
+  (= (rank element) (1- (nb-elements (chain element)))))
+
 (defmethod flexi-next ((element element-rank-mixin))
-  (let ((new-rank (1+ (rank element)))
-	(chain (chain element)))
-    (assert (< new-rank (nb-elements chain)))
-    (element* chain new-rank)))
+  (assert (not (flexi-last-p element)))
+  (element* (chain element) (1+ (rank element))))
 
 (defmethod flexi-prev ((element element-rank-mixin))
-  (let ((new-rank (1- (rank element))))
-    (assert (not (minusp new-rank)))
-    (element* (chain element) new-rank)))
+  (assert (not (flexi-first-p element)))
+  (element* (chain element) (1- (rank element))))
 
 ;;; this class must be mixed into a flexichain that contains ranked elements
 (defclass flexirank-mixin () ())




More information about the Gsharp-cvs mailing list