[funds-cvs] r78 - trunk/funds/src/trees

abaine at common-lisp.net abaine at common-lisp.net
Wed Jul 11 02:46:47 UTC 2007


Author: abaine
Date: Tue Jul 10 22:46:47 2007
New Revision: 78

Modified:
   trunk/funds/src/trees/avl.lisp
Log:
Refactored make-avl-tree calls into attach-avl function.

Modified: trunk/funds/src/trees/avl.lisp
==============================================================================
--- trunk/funds/src/trees/avl.lisp	(original)
+++ trunk/funds/src/trees/avl.lisp	Tue Jul 10 22:46:47 2007
@@ -37,10 +37,9 @@
 (defun balance (inside root outside &key heavy-side)
   (let ((other-side (other-side heavy-side)))
     (if (balanced-p inside outside) 
-	(make-avl-tree :key (bt-key root)
-		       :value (bt-value root)
-		       heavy-side outside
-		       other-side inside)
+	(attach-avl root
+		    heavy-side outside
+		    other-side inside)
 	(rotate inside root
 		(if (heavier-p outside :side other-side)
 		    (rotate (tree-child outside :side heavy-side)
@@ -52,13 +51,16 @@
 
 (defun rotate (inside root outside &key side)
   (let* ((t1 (tree-child outside :side side))
-	 (new-inside (make-avl-tree :key (bt-key root)
-				    :value (bt-value root)
-				    side inside
-				    (other-side side) t1))
+	 (new-inside (attach-avl root
+				 side inside
+				 (other-side side) t1))
 	 (new-outside (tree-child outside :side (other-side side))))
-    (make-avl-tree
-		   :key (bt-key outside)
-		   :value (bt-key outside)
-		   side new-inside
-		   (other-side side) new-outside)))
+    (attach-avl outside
+		side new-inside
+		(other-side side) new-outside)))
+
+(defun attach-avl (root &key (right (make-avl-tree)) (left (make-avl-tree)))
+  (make-avl-tree :key (bt-key root)
+		 :value (bt-key root)
+		 :right right
+		 :left left))



More information about the Funds-cvs mailing list