]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/avl-tree.el (avl-tree--enter-balance): Fix paren typo.
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 27 Mar 2012 20:43:09 +0000 (16:43 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 27 Mar 2012 20:43:09 +0000 (16:43 -0400)
(avl-tree--check, avl-tree--check-node): New funs.

Fixes: debbugs:11077
lisp/ChangeLog
lisp/emacs-lisp/avl-tree.el

index 7d81bbb46b5c28b3fe569b6b1aec051818c3a1dc..65018db7e4dc1053ed83ba14e4e265aa5792f19f 100644 (file)
@@ -1,8 +1,14 @@
+2012-03-27  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * emacs-lisp/avl-tree.el (avl-tree--enter-balance): Fix paren typo
+       (bug#11077).
+       (avl-tree--check, avl-tree--check-node): New funs.
+
 2012-03-27  Martin Rudalics  <rudalics@gmx.at>
 
        * window.el (switch-to-visible-buffer): New option.
-       (switch-to-prev-buffer, switch-to-next-buffer): Observe
-       switch-to-visible-buffer.  Make sure that checking for a window
+       (switch-to-prev-buffer, switch-to-next-buffer):
+       Observe switch-to-visible-buffer.  Make sure that checking for a window
        showing a buffer already is done on the same frame.
 
 2012-03-27  Glenn Morris  <rgm@gnu.org>
@@ -28,8 +34,7 @@
 2012-03-25  Eli Zaretskii  <eliz@gnu.org>
 
        * makefile.w32-in (install): Use $(DIRNAME)_same-dir.tst instead
-       of same-dir.tst, to avoid stepping on other (parallel) Make job's
-       toes.
+       of same-dir.tst, to avoid stepping on other (parallel) Make job's toes.
 
 2012-03-25  Chong Yidong  <cyd@gnu.org>
 
index cb5ea048999f14599f3c5ec5495b1d15157966ae..9f3487674781372ff936c3bc51db20770c2fb9ee 100644 (file)
@@ -295,9 +295,9 @@ Return t if the height of the tree has grown."
                (if (> (* sgn b2) 0) (- sgn) 0)
              (avl-tree--node-balance p1)
                (if (< (* sgn b2) 0) sgn 0)
-             (avl-tree--node-branch node branch) p2
-             (avl-tree--node-balance
-              (avl-tree--node-branch node branch)) 0))
+                (avl-tree--node-branch node branch) p2))
+      (setf (avl-tree--node-balance
+             (avl-tree--node-branch node branch)) 0)
       nil))))
 
 (defun avl-tree--do-enter (cmpfun root branch data &optional updatefun)
@@ -339,6 +339,16 @@ inserted data."
        (cons nil newdata))  ; return value
       ))))
 
+(defun avl-tree--check (tree)
+  "Check the tree's balance."
+  (avl-tree--check-node (avl-tree--root tree)))
+(defun avl-tree--check-node (node)
+  (if (null node) 0
+    (let ((dl (avl-tree--check-node (avl-tree--node-left node)))
+         (dr (avl-tree--check-node (avl-tree--node-right node))))
+      (assert (= (- dr dl) (avl-tree--node-balance node)))
+      (1+ (max dl dr)))))
+
 ;; ----------------------------------------------------------------