diff options
| author | Thien-Thi Nguyen | 2007-08-27 03:09:15 +0000 |
|---|---|---|
| committer | Thien-Thi Nguyen | 2007-08-27 03:09:15 +0000 |
| commit | d385b030e7924a8ef5d7df63b25ce12e3fbd6311 (patch) | |
| tree | 544d1011e756e24399e827c0ba9786bf56137235 | |
| parent | 8fa134424913ad16f2b95f1d1cb2992d3fd17059 (diff) | |
| download | emacs-d385b030e7924a8ef5d7df63b25ce12e3fbd6311.tar.gz emacs-d385b030e7924a8ef5d7df63b25ce12e3fbd6311.zip | |
Commentary and docstring munging; nfc.
| -rw-r--r-- | lisp/emacs-lisp/avl-tree.el | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/lisp/emacs-lisp/avl-tree.el b/lisp/emacs-lisp/avl-tree.el index 074f8e7c772..ffac825acac 100644 --- a/lisp/emacs-lisp/avl-tree.el +++ b/lisp/emacs-lisp/avl-tree.el | |||
| @@ -28,19 +28,6 @@ | |||
| 28 | 28 | ||
| 29 | ;;; Commentary: | 29 | ;;; Commentary: |
| 30 | 30 | ||
| 31 | ;; This file combines elib-node.el and avltree.el from Elib. | ||
| 32 | ;; | ||
| 33 | ;; * Comments from elib-node.el | ||
| 34 | ;; A node is implemented as an array with three elements, using | ||
| 35 | ;; (elt node 0) as the left pointer | ||
| 36 | ;; (elt node 1) as the right pointer | ||
| 37 | ;; (elt node 2) as the data | ||
| 38 | ;; | ||
| 39 | ;; Some types of trees, e.g. AVL trees, need bigger nodes, but | ||
| 40 | ;; as long as the first three parts are the left pointer, the | ||
| 41 | ;; right pointer and the data field, these macros can be used. | ||
| 42 | ;; | ||
| 43 | ;; * Comments from avltree.el | ||
| 44 | ;; An AVL tree is a nearly-perfect balanced binary tree. A tree | 31 | ;; An AVL tree is a nearly-perfect balanced binary tree. A tree |
| 45 | ;; consists of two cons cells, the first one holding the tag | 32 | ;; consists of two cons cells, the first one holding the tag |
| 46 | ;; 'AVL-TREE in the car cell, and the second one having the tree | 33 | ;; 'AVL-TREE in the car cell, and the second one having the tree |
| @@ -51,6 +38,10 @@ | |||
| 51 | ;; sub-tree and one right sub-tree. Each node also has a balance | 38 | ;; sub-tree and one right sub-tree. Each node also has a balance |
| 52 | ;; count, which is the difference in depth of the left and right | 39 | ;; count, which is the difference in depth of the left and right |
| 53 | ;; sub-trees. | 40 | ;; sub-trees. |
| 41 | ;; | ||
| 42 | ;; The "public" functions (prefixed with "avl-tree") are: | ||
| 43 | ;; -create, -p, -compare-function, -empty, -enter, -delete, | ||
| 44 | ;; -member, -map, -first, -last, -copy, -flatten, -size, -clear. | ||
| 54 | 45 | ||
| 55 | ;;; Code: | 46 | ;;; Code: |
| 56 | 47 | ||
| @@ -86,18 +77,18 @@ | |||
| 86 | `(aset ,node 2 ,newdata)) | 77 | `(aset ,node 2 ,newdata)) |
| 87 | 78 | ||
| 88 | (defmacro avl-tree-node-branch (node branch) | 79 | (defmacro avl-tree-node-branch (node branch) |
| 89 | ;; Get value of a branch of a node. | 80 | "Get value of a branch of a node. |
| 90 | ;; | 81 | |
| 91 | ;; NODE is the node, and BRANCH is the branch. | 82 | NODE is the node, and BRANCH is the branch. |
| 92 | ;; 0 for left pointer, 1 for right pointer and 2 for the data." | 83 | 0 for left pointer, 1 for right pointer and 2 for the data.\"" |
| 93 | `(aref ,node ,branch)) | 84 | `(aref ,node ,branch)) |
| 94 | 85 | ||
| 95 | (defmacro avl-tree-node-set-branch (node branch newval) | 86 | (defmacro avl-tree-node-set-branch (node branch newval) |
| 96 | ;; Set value of a branch of a node. | 87 | "Set value of a branch of a node. |
| 97 | ;; | 88 | |
| 98 | ;; NODE is the node, and BRANCH is the branch. | 89 | NODE is the node, and BRANCH is the branch. |
| 99 | ;; 0 for left pointer, 1 for the right pointer and 2 for the data. | 90 | 0 for left pointer, 1 for the right pointer and 2 for the data. |
| 100 | ;; NEWVAL is new value of the branch." | 91 | NEWVAL is new value of the branch.\"" |
| 101 | `(aset ,node ,branch ,newval)) | 92 | `(aset ,node ,branch ,newval)) |
| 102 | 93 | ||
| 103 | (defmacro avl-tree-node-balance (node) | 94 | (defmacro avl-tree-node-balance (node) |
| @@ -402,7 +393,7 @@ | |||
| 402 | go-left nil)))))) | 393 | go-left nil)))))) |
| 403 | 394 | ||
| 404 | (defun avl-tree-do-copy (root) | 395 | (defun avl-tree-do-copy (root) |
| 405 | ;; Copy the tree with ROOT as root. | 396 | ;; Copy the avl tree with ROOT as root. |
| 406 | ;; Highly recursive. INTERNAL USE ONLY. | 397 | ;; Highly recursive. INTERNAL USE ONLY. |
| 407 | (if (null root) | 398 | (if (null root) |
| 408 | nil | 399 | nil |
| @@ -417,7 +408,7 @@ | |||
| 417 | ;;; The public functions which operate on AVL trees. | 408 | ;;; The public functions which operate on AVL trees. |
| 418 | 409 | ||
| 419 | (defun avl-tree-create (compare-function) | 410 | (defun avl-tree-create (compare-function) |
| 420 | "Create an empty avl tree. | 411 | "Create a new empty avl tree and return it. |
| 421 | COMPARE-FUNCTION is a function which takes two arguments, A and B, | 412 | COMPARE-FUNCTION is a function which takes two arguments, A and B, |
| 422 | and returns non-nil if A is less than B, and nil otherwise." | 413 | and returns non-nil if A is less than B, and nil otherwise." |
| 423 | (cons 'AVL-TREE | 414 | (cons 'AVL-TREE |
| @@ -429,11 +420,11 @@ and returns non-nil if A is less than B, and nil otherwise." | |||
| 429 | (eq (car-safe obj) 'AVL-TREE)) | 420 | (eq (car-safe obj) 'AVL-TREE)) |
| 430 | 421 | ||
| 431 | (defun avl-tree-compare-function (tree) | 422 | (defun avl-tree-compare-function (tree) |
| 432 | "Return the comparision function for the avl tree TREE." | 423 | "Return the comparison function for the avl tree TREE." |
| 433 | (avl-tree-cmpfun tree)) | 424 | (avl-tree-cmpfun tree)) |
| 434 | 425 | ||
| 435 | (defun avl-tree-empty (tree) | 426 | (defun avl-tree-empty (tree) |
| 436 | "Return t if TREE is emtpy, otherwise return nil." | 427 | "Return t if avl tree TREE is emtpy, otherwise return nil." |
| 437 | (null (avl-tree-root tree))) | 428 | (null (avl-tree-root tree))) |
| 438 | 429 | ||
| 439 | (defun avl-tree-enter (tree data) | 430 | (defun avl-tree-enter (tree data) |
| @@ -447,7 +438,8 @@ Return DATA." | |||
| 447 | 438 | ||
| 448 | (defun avl-tree-delete (tree data) | 439 | (defun avl-tree-delete (tree data) |
| 449 | "From the avl tree TREE, delete DATA. | 440 | "From the avl tree TREE, delete DATA. |
| 450 | Return the element in TREE which matched DATA, nil if no element matched." | 441 | Return the element in TREE which matched DATA, |
| 442 | nil if no element matched." | ||
| 451 | (avl-tree-do-delete (avl-tree-cmpfun tree) | 443 | (avl-tree-do-delete (avl-tree-cmpfun tree) |
| 452 | (avl-tree-dummyroot tree) | 444 | (avl-tree-dummyroot tree) |
| 453 | 0 | 445 | 0 |
| @@ -455,8 +447,8 @@ Return the element in TREE which matched DATA, nil if no element matched." | |||
| 455 | 447 | ||
| 456 | (defun avl-tree-member (tree data) | 448 | (defun avl-tree-member (tree data) |
| 457 | "Return the element in the avl tree TREE which matches DATA. | 449 | "Return the element in the avl tree TREE which matches DATA. |
| 458 | Matching uses the compare function previously specified in `avl-tree-create' | 450 | Matching uses the compare function previously specified in |
| 459 | when TREE was created. | 451 | `avl-tree-create' when TREE was created. |
| 460 | 452 | ||
| 461 | If there is no such element in the tree, the value is nil." | 453 | If there is no such element in the tree, the value is nil." |
| 462 | (let ((node (avl-tree-root tree)) | 454 | (let ((node (avl-tree-root tree)) |
| @@ -476,7 +468,7 @@ If there is no such element in the tree, the value is nil." | |||
| 476 | nil))) | 468 | nil))) |
| 477 | 469 | ||
| 478 | (defun avl-tree-map (__map-function__ tree) | 470 | (defun avl-tree-map (__map-function__ tree) |
| 479 | "Apply MAP-FUNCTION to all elements in the avl tree TREE." | 471 | "Apply __MAP-FUNCTION__ to all elements in the avl tree TREE." |
| 480 | (avl-tree-mapc | 472 | (avl-tree-mapc |
| 481 | (function (lambda (node) | 473 | (function (lambda (node) |
| 482 | (avl-tree-node-set-data | 474 | (avl-tree-node-set-data |