aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2021-04-28 19:36:42 +0300
committerEli Zaretskii2021-04-28 19:36:42 +0300
commit2feeebe40a198ae1876f86574df9a27ea82ecdd8 (patch)
tree1454cfea3d901130f8b98efc255146b122e16785
parent4fc6afb913ad24ab4796daf6a9409f497a804e85 (diff)
downloademacs-2feeebe40a198ae1876f86574df9a27ea82ecdd8.tar.gz
emacs-2feeebe40a198ae1876f86574df9a27ea82ecdd8.zip
Doc fixes in avl-tree.el
* lisp/emacs-lisp/avl-tree.el (avl-tree--root) (avl-tree--dir-to-sign, avl-tree--sign-to-dir) (avl-tree--del-balance, avl-tree--enter-balance) (avl-tree--do-copy, avl-tree--stack-repopulate, avl-tree-empty) (avl-tree-delete, avl-tree-member, avl-tree-member-p) (avl-tree-map, avl-tree-mapc, avl-tree-mapf, avl-tree-mapcar) (avl-tree-copy, avl-tree-clear, avl-tree-stack) (avl-tree-stack-first): Fix doc strings to be less verbose and to have the first line a complete sentence.
-rw-r--r--lisp/emacs-lisp/avl-tree.el51
1 files changed, 24 insertions, 27 deletions
diff --git a/lisp/emacs-lisp/avl-tree.el b/lisp/emacs-lisp/avl-tree.el
index c8c96fa8223..4382985eb85 100644
--- a/lisp/emacs-lisp/avl-tree.el
+++ b/lisp/emacs-lisp/avl-tree.el
@@ -74,7 +74,7 @@
74 cmpfun) 74 cmpfun)
75 75
76(defmacro avl-tree--root (tree) 76(defmacro avl-tree--root (tree)
77 "Return the root node for an AVL tree. INTERNAL USE ONLY." 77 "Return the root node for an AVL TREE. INTERNAL USE ONLY."
78 `(avl-tree--node-left (avl-tree--dummyroot ,tree))) 78 `(avl-tree--node-left (avl-tree--dummyroot ,tree)))
79 79
80;; ---------------------------------------------------------------- 80;; ----------------------------------------------------------------
@@ -117,11 +117,11 @@ NODE is the node, and BRANCH is the branch.
117 `(- 1 ,dir)) 117 `(- 1 ,dir))
118 118
119(defmacro avl-tree--dir-to-sign (dir) 119(defmacro avl-tree--dir-to-sign (dir)
120 "Convert direction (0,1) to sign factor (-1,+1)." 120 "Convert direction DIR (0,1) to sign factor (-1,+1)."
121 `(1- (* 2 ,dir))) 121 `(1- (* 2 ,dir)))
122 122
123(defmacro avl-tree--sign-to-dir (dir) 123(defmacro avl-tree--sign-to-dir (dir)
124 "Convert sign factor (-x,+x) to direction (0,1)." 124 "Convert sign factor in DIR (-x,+x) to direction (0,1)."
125 `(if (< ,dir 0) 0 1)) 125 `(if (< ,dir 0) 0 1))
126 126
127 127
@@ -129,7 +129,7 @@ NODE is the node, and BRANCH is the branch.
129;; Deleting data 129;; Deleting data
130 130
131(defun avl-tree--del-balance (node branch dir) 131(defun avl-tree--del-balance (node branch dir)
132 "Rebalance a tree after deleting a node. 132 "Rebalance a tree after deleting a NODE.
133The deletion was done from the left (DIR=0) or right (DIR=1) sub-tree 133The deletion was done from the left (DIR=0) or right (DIR=1) sub-tree
134of the left (BRANCH=0) or right (BRANCH=1) child of NODE. 134of the left (BRANCH=0) or right (BRANCH=1) child of NODE.
135Return t if the height of the tree has shrunk." 135Return t if the height of the tree has shrunk."
@@ -247,9 +247,9 @@ the related data."
247;; Entering data 247;; Entering data
248 248
249(defun avl-tree--enter-balance (node branch dir) 249(defun avl-tree--enter-balance (node branch dir)
250 "Rebalance tree after an insertion 250 "Rebalance tree after insertion of NODE.
251into the left (DIR=0) or right (DIR=1) sub-tree of the 251NODE was inserted into the left (DIR=0) or right (DIR=1) sub-tree
252left (BRANCH=0) or right (BRANCH=1) child of NODE. 252of the left (BRANCH=0) or right (BRANCH=1) child of NODE.
253Return t if the height of the tree has grown." 253Return t if the height of the tree has grown."
254 (let ((br (avl-tree--node-branch node branch)) 254 (let ((br (avl-tree--node-branch node branch))
255 ;; opposite direction: 0,1 -> 1,0 255 ;; opposite direction: 0,1 -> 1,0
@@ -379,7 +379,8 @@ itself."
379 379
380;;; INTERNAL USE ONLY 380;;; INTERNAL USE ONLY
381(defun avl-tree--do-copy (root) 381(defun avl-tree--do-copy (root)
382 "Copy the AVL tree with ROOT as root. Highly recursive." 382 "Copy the AVL tree wiath ROOT as root.
383This function is highly recursive."
383 (if (null root) 384 (if (null root)
384 nil 385 nil
385 (avl-tree--node-create 386 (avl-tree--node-create
@@ -405,8 +406,9 @@ itself."
405\n(fn OBJ)") 406\n(fn OBJ)")
406 407
407(defun avl-tree--stack-repopulate (stack) 408(defun avl-tree--stack-repopulate (stack)
408 "Recursively push children of the node at the head of STACK onto the 409 "Recursively push children of STACK onto the front.
409front of the STACK, until a leaf is reached." 410This pushes the children of the node at the head of STACK onto
411the front of STACK, until a leaf node is reached."
410 (let ((node (car (avl-tree--stack-store stack))) 412 (let ((node (car (avl-tree--stack-store stack)))
411 (dir (if (avl-tree--stack-reverse stack) 1 0))) 413 (dir (if (avl-tree--stack-reverse stack) 1 0)))
412 (when node ; check for empty stack 414 (when node ; check for empty stack
@@ -429,7 +431,7 @@ and returns non-nil if A is less than B, and nil otherwise.
429\n(fn TREE)") 431\n(fn TREE)")
430 432
431(defun avl-tree-empty (tree) 433(defun avl-tree-empty (tree)
432 "Return t if AVL tree TREE is empty, otherwise return nil." 434 "Return t if AVL TREE is empty, otherwise return nil."
433 (null (avl-tree--root tree))) 435 (null (avl-tree--root tree)))
434 436
435(defun avl-tree-enter (tree data &optional updatefun) 437(defun avl-tree-enter (tree data &optional updatefun)
@@ -451,7 +453,7 @@ Returns the new data."
451 0 data updatefun))) 453 0 data updatefun)))
452 454
453(defun avl-tree-delete (tree data &optional test nilflag) 455(defun avl-tree-delete (tree data &optional test nilflag)
454 "Delete the element matching DATA from the AVL tree TREE. 456 "Delete the element matching DATA from the AVL TREE.
455Matching uses the comparison function previously specified in 457Matching uses the comparison function previously specified in
456`avl-tree-create' when TREE was created. 458`avl-tree-create' when TREE was created.
457 459
@@ -473,7 +475,7 @@ value is non-nil."
473 475
474 476
475(defun avl-tree-member (tree data &optional nilflag) 477(defun avl-tree-member (tree data &optional nilflag)
476 "Return the element in the AVL tree TREE which matches DATA. 478 "Return the element in the AVL TREE which matches DATA.
477Matching uses the comparison function previously specified in 479Matching uses the comparison function previously specified in
478`avl-tree-create' when TREE was created. 480`avl-tree-create' when TREE was created.
479 481
@@ -496,7 +498,7 @@ for you.)"
496 498
497 499
498(defun avl-tree-member-p (tree data) 500(defun avl-tree-member-p (tree data)
499 "Return t if an element matching DATA exists in the AVL tree TREE. 501 "Return t if an element matching DATA exists in the AVL TREE.
500Otherwise return nil. Matching uses the comparison function 502Otherwise return nil. Matching uses the comparison function
501previously specified in `avl-tree-create' when TREE was created." 503previously specified in `avl-tree-create' when TREE was created."
502 (let ((flag '(nil))) 504 (let ((flag '(nil)))
@@ -504,7 +506,7 @@ previously specified in `avl-tree-create' when TREE was created."
504 506
505 507
506(defun avl-tree-map (fun tree &optional reverse) 508(defun avl-tree-map (fun tree &optional reverse)
507 "Modify all elements in the AVL tree TREE by applying function FUN. 509 "Modify all elements in the AVL TREE by applying function FUN.
508 510
509Each element is replaced by the return value of FUN applied to 511Each element is replaced by the return value of FUN applied to
510that element. 512that element.
@@ -520,8 +522,7 @@ order if REVERSE is non-nil."
520 522
521 523
522(defun avl-tree-mapc (fun tree &optional reverse) 524(defun avl-tree-mapc (fun tree &optional reverse)
523 "Apply function FUN to all elements in AVL tree TREE, 525 "Apply function FUN to all elements in AVL TREE, for side-effect only.
524for side-effect only.
525 526
526FUNCTION is applied to the elements in ascending order, or 527FUNCTION is applied to the elements in ascending order, or
527descending order if REVERSE is non-nil." 528descending order if REVERSE is non-nil."
@@ -534,8 +535,7 @@ descending order if REVERSE is non-nil."
534 535
535(defun avl-tree-mapf 536(defun avl-tree-mapf
536 (fun combinator tree &optional reverse) 537 (fun combinator tree &optional reverse)
537 "Apply function FUN to all elements in AVL tree TREE, 538 "Apply FUN to all elements in AVL TREE, combine results using COMBINATOR.
538and combine the results using COMBINATOR.
539 539
540The FUNCTION is applied and the results are combined in ascending 540The FUNCTION is applied and the results are combined in ascending
541order, or descending order if REVERSE is non-nil." 541order, or descending order if REVERSE is non-nil."
@@ -553,8 +553,7 @@ order, or descending order if REVERSE is non-nil."
553 553
554 554
555(defun avl-tree-mapcar (fun tree &optional reverse) 555(defun avl-tree-mapcar (fun tree &optional reverse)
556 "Apply function FUN to all elements in AVL tree TREE, 556 "Apply FUN to all elements in AVL TREE, and make a list of the results.
557and make a list of the results.
558 557
559The function is applied and the list constructed in ascending 558The function is applied and the list constructed in ascending
560order, or descending order if REVERSE is non-nil. 559order, or descending order if REVERSE is non-nil.
@@ -586,7 +585,7 @@ is more efficient."
586 (avl-tree--node-data node)))) 585 (avl-tree--node-data node))))
587 586
588(defun avl-tree-copy (tree) 587(defun avl-tree-copy (tree)
589 "Return a copy of the AVL tree TREE." 588 "Return a copy of the AVL TREE."
590 (let ((new-tree (avl-tree-create (avl-tree--cmpfun tree)))) 589 (let ((new-tree (avl-tree-create (avl-tree--cmpfun tree))))
591 (setf (avl-tree--root new-tree) (avl-tree--do-copy (avl-tree--root tree))) 590 (setf (avl-tree--root new-tree) (avl-tree--do-copy (avl-tree--root tree)))
592 new-tree)) 591 new-tree))
@@ -608,13 +607,12 @@ is more efficient."
608 treesize)) 607 treesize))
609 608
610(defun avl-tree-clear (tree) 609(defun avl-tree-clear (tree)
611 "Clear the AVL tree TREE." 610 "Clear the AVL TREE."
612 (setf (avl-tree--root tree) nil)) 611 (setf (avl-tree--root tree) nil))
613 612
614 613
615(defun avl-tree-stack (tree &optional reverse) 614(defun avl-tree-stack (tree &optional reverse)
616 "Return an object that behaves like a sorted stack 615 "Return an object that behaves like a sorted stack of all elements of TREE.
617of all elements of TREE.
618 616
619If REVERSE is non-nil, the stack is sorted in reverse order. 617If REVERSE is non-nil, the stack is sorted in reverse order.
620\(See also `avl-tree-stack-pop'). 618\(See also `avl-tree-stack-pop').
@@ -655,8 +653,7 @@ a null element stored in the AVL tree.)"
655 653
656 654
657(defun avl-tree-stack-first (avl-tree-stack &optional nilflag) 655(defun avl-tree-stack-first (avl-tree-stack &optional nilflag)
658 "Return the first element of AVL-TREE-STACK, without removing it 656 "Return the first element of AVL-TREE-STACK, without removing it from stack.
659from the stack.
660 657
661Returns nil if the stack is empty, or NILFLAG if specified. 658Returns nil if the stack is empty, or NILFLAG if specified.
662\(The latter allows an empty stack to be distinguished from 659\(The latter allows an empty stack to be distinguished from