;;; rtree.el --- functions for manipulating range trees
-;; Copyright (C) 2010 Free Software Foundation, Inc.
+
+;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(setq parent successor
successor (rtree-left successor)))
;; We now have the leftmost child of our right child.
- (rtree-set-range (rtree-range successor))
+ (rtree-set-range tree (rtree-range successor))
;; Transplant the child (if any) to the parent.
(rtree-set-left parent (rtree-right successor))))
(t
(let ((predecessor (rtree-left tree)))
(while (rtree-right predecessor)
(setq predecessor (rtree-right predecessor)))
- (rtree-set-right predecessor new-mode)))
+ (rtree-set-right predecessor new-node)))
((rtree-left tree)
(rtree-set-right new-node tree)
(rtree-set-left new-node (rtree-left tree))
(setq tree (rtree-left tree))))
result))
+(defun rtree-length (tree)
+ "Return the number of numbers stored in TREE."
+ (if (null tree)
+ 0
+ (+ (rtree-length (rtree-left tree))
+ (1+ (- (rtree-high tree)
+ (rtree-low tree)))
+ (rtree-length (rtree-right tree)))))
+
(provide 'rtree)
;;; rtree.el ends here