summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/avl-tree.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/avl-tree.el')
-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