Function: ewoc--node-nth

ewoc--node-nth is a byte-compiled function defined in ewoc.el.gz.

Signature

(ewoc--node-nth DLL N)

Documentation

Return the Nth node from the doubly linked list DLL.

N counts from zero. If N is negative, return the -(N+1)th last element. If N is out of range, return nil. Thus, (ewoc--node-nth dll 0) returns the first node, and (ewoc--node-nth dll -1) returns the last node.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/ewoc.el.gz
(defun ewoc--node-nth (dll n)
  "Return the Nth node from the doubly linked list DLL.
N counts from zero.  If N is negative, return the -(N+1)th last element.
If N is out of range, return nil.
Thus, (ewoc--node-nth dll 0) returns the first node,
and (ewoc--node-nth dll -1) returns the last node."
  ;; Presuming a node is ":type vector", starting with `left' and `right':
  ;; Branch 0 ("follow left pointer") is used when n is negative.
  ;; Branch 1 ("follow right pointer") is used otherwise.
  (let* ((branch (if (< n 0) 0 1))
	 (node   (aref dll branch)))
    (if (< n 0) (setq n (- -1 n)))
    (while (and (not (eq dll node)) (> n 0))
      (setq node (aref node branch))
      (setq n (1- n)))
    (unless (eq dll node) node)))