Function: avl-tree--do-delete

avl-tree--do-delete is a byte-compiled function defined in avl-tree.el.gz.

Signature

(avl-tree--do-delete CMPFUN ROOT BRANCH DATA TEST NILFLAG)

Documentation

Delete DATA from BRANCH of node ROOT.

(See avl-tree-delete for TEST and NILFLAG).

Return cons cell (SHRUNK . DATA), where SHRUNK is t if the height of the tree has shrunk and nil otherwise, and DATA is the related data.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/avl-tree.el.gz
(defun avl-tree--do-delete (cmpfun root branch data test nilflag)
  "Delete DATA from BRANCH of node ROOT.
\(See `avl-tree-delete' for TEST and NILFLAG).

Return cons cell (SHRUNK . DATA), where SHRUNK is t if the
height of the tree has shrunk and nil otherwise, and DATA is
the related data."
  (let ((br (avl-tree--node-branch root branch)))
    (cond
     ;; DATA not in tree.
     ((null br)
      (cons nil nilflag))

     ((funcall cmpfun data (avl-tree--node-data br))
      (let ((ret (avl-tree--do-delete cmpfun br 0 data test nilflag)))
	(cons (if (car ret) (avl-tree--del-balance root branch 0))
	      (cdr ret))))

     ((funcall cmpfun (avl-tree--node-data br) data)
      (let ((ret (avl-tree--do-delete cmpfun br 1 data test nilflag)))
	(cons (if (car ret) (avl-tree--del-balance root branch 1))
	      (cdr ret))))

     (t  ; Found it.
      ;; if it fails TEST, do nothing
      (if (and test (not (funcall test (avl-tree--node-data br))))
	  (cons nil nilflag)
	(cond
	 ((null (avl-tree--node-right br))
	  (setf (avl-tree--node-branch root branch)
		(avl-tree--node-left br))
	  (cons t (avl-tree--node-data br)))

	 ((null (avl-tree--node-left br))
	  (setf (avl-tree--node-branch root branch)
		(avl-tree--node-right br))
	  (cons t (avl-tree--node-data br)))

	 (t
	  (if (avl-tree--do-del-internal br 0 br)
	      (cons (avl-tree--del-balance root branch 0)
		    (avl-tree--node-data br))
	    (cons nil (avl-tree--node-data br))))
	 ))))))