[funds-cvs] r114 - trunk/funds/src/trees
abaine at common-lisp.net
abaine at common-lisp.net
Sat Aug 4 14:03:17 UTC 2007
Author: abaine
Date: Sat Aug 4 10:03:17 2007
New Revision: 114
Added:
trunk/funds/src/trees/stitch-tree.lisp
Log:
Added stitch-tree methods and
functions to replace constructors. These are responsible for making sure that the nodes
that are stitched together actually satisfy avl properties in the case of avl trees.
Added: trunk/funds/src/trees/stitch-tree.lisp
==============================================================================
--- (empty file)
+++ trunk/funds/src/trees/stitch-tree.lisp Sat Aug 4 10:03:17 2007
@@ -0,0 +1,41 @@
+
+;;;;
+;;;; Copyright 2007 Andrew Baine
+;;;;
+;;;; Licensed under the Apache License, Version 2.0 (the "License");
+;;;; you may not use this file except in compliance with the License.
+;;;; You may obtain a copy of the License at
+;;;;
+;;;; http://www.apache.org/licenses/LICENSE-2.0
+;;;;
+;;;; Unless required by applicable law or agreed to in writing, software
+;;;; distributed under the License is distributed on an "AS IS" BASIS,
+;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;;;; See the License for the specific language governing permissions and
+;;;; limitations under the License.
+;;;;
+
+(in-package :funds)
+
+(defmethod stitch-tree ((tree binary-tree)
+ &key (key (bt-key tree)) (value (bt-value tree)) left right)
+ (stitch-binary-tree :key key :value value :left left :right right))
+
+(defmethod stitch-tree ((tree avl-tree)
+ &key (key (bt-key tree)) (value (bt-value tree)) left right)
+ (balance key value left right))
+
+(defun stitch-avl-tree (&key root (key (bt-key root)) (value (bt-value root))
+ (left (make-avl-leaf)) (right (make-avl-leaf)))
+ (make-instance 'avl-tree
+ :key key :value value
+ :left left :right right
+ :height (parent-height left right)))
+
+(defun stitch-binary-tree (&key root (key (bt-key root)) (value (bt-value root))
+ (left (make-binary-tree)) (right (make-binary-tree)))
+ (make-instance 'binary-tree
+ :key key
+ :value value
+ :left left
+ :right right))
More information about the Funds-cvs
mailing list