summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorToby S. Cubitt <tsc25@cantab.net>2017-08-04 20:34:28 +0100
committerToby S. Cubitt <tsc25@cantab.net>2017-08-04 20:39:05 +0100
commit4b7f822cd53a50e83008ab4f561563d8977a74ec (patch)
treea2980b5bcf9a2e329805f8956f81bc31bab6e499 /lisp/emacs-lisp
parent929c60603ca19574159c78f12f5f953c31188bc6 (diff)
downloademacs-4b7f822cd53a50e83008ab4f561563d8977a74ec.tar.gz
emacs-4b7f822cd53a50e83008ab4f561563d8977a74ec.tar.bz2
emacs-4b7f822cd53a50e83008ab4f561563d8977a74ec.zip
Implement iterator generator for avl-trees.
* lisp/emacs-lisp/avl-tree.el (avl-tree-iter): New iter-defun.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/avl-tree.el17
1 files changed, 16 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/avl-tree.el b/lisp/emacs-lisp/avl-tree.el
index 17f1ffa9f61..32f7d2c6d8d 100644
--- a/lisp/emacs-lisp/avl-tree.el
+++ b/lisp/emacs-lisp/avl-tree.el
@@ -52,7 +52,7 @@
;;; Code:
(eval-when-compile (require 'cl-lib))
-
+(require 'generator)
;; ================================================================
@@ -670,6 +670,21 @@ a null element stored in the AVL tree.)"
(null (avl-tree--stack-store avl-tree-stack)))
+(iter-defun avl-tree-iter (tree &optional reverse)
+ "Return an AVL tree iterator object.
+
+Calling `iter-next' on this object will retrieve the next element
+from TREE. If REVERSE is non-nil, elements are returned in
+reverse order.
+
+Note that any modification to TREE *immediately* invalidates all
+iterators created from TREE before the modification (in
+particular, calling `iter-next' will give unpredictable results)."
+ (let ((stack (avl-tree-stack tree reverse)))
+ (while (not (avl-tree-stack-empty-p stack))
+ (iter-yield (avl-tree-stack-pop stack)))))
+
+
(provide 'avl-tree)
;;; avl-tree.el ends here