Mercurial > emacs
comparison lisp/emacs-lisp/ewoc.el @ 70994:d3750d5046d7
(ewoc--node-branch): Merge into unique caller.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Sat, 27 May 2006 10:09:22 +0000 |
parents | dcab6d42213c |
children | 9a4ed4323ed7 |
comparison
equal
deleted
inserted
replaced
70993:320310f2740c | 70994:d3750d5046d7 |
---|---|
137 ;; "the dll" (or rather the dynamically bound `ewoc--current-dll'). | 137 ;; "the dll" (or rather the dynamically bound `ewoc--current-dll'). |
138 | 138 |
139 (defvar ewoc--current-dll) | 139 (defvar ewoc--current-dll) |
140 | 140 |
141 (defstruct (ewoc--node | 141 (defstruct (ewoc--node |
142 (:type vector) ;required for ewoc--node-branch hack | 142 (:type vector) ;ewoc--node-nth needs this |
143 (:constructor ewoc--node-create (start-marker data))) | 143 (:constructor ewoc--node-create (start-marker data))) |
144 left right data start-marker) | 144 left right data start-marker) |
145 | |
146 (defalias 'ewoc--node-branch 'aref | |
147 "Get the left (CHILD=0) or right (CHILD=1) child of the NODE. | |
148 | |
149 \(fn NODE CHILD)") | |
150 | 145 |
151 (defun ewoc--node-next (node) | 146 (defun ewoc--node-next (node) |
152 "Return the node after NODE, or nil if NODE is the last node." | 147 "Return the node after NODE, or nil if NODE is the last node." |
153 (let ((R (ewoc--node-right node))) | 148 (let ((R (ewoc--node-right node))) |
154 (unless (eq ewoc--current-dll R) R))) | 149 (unless (eq ewoc--current-dll R) R))) |
162 "Return the Nth node from the doubly linked list `ewoc--current-dll'. | 157 "Return the Nth node from the doubly linked list `ewoc--current-dll'. |
163 N counts from zero. If N is negative, return the -(N+1)th last element. | 158 N counts from zero. If N is negative, return the -(N+1)th last element. |
164 If N is out of range, return nil. | 159 If N is out of range, return nil. |
165 Thus, (ewoc--node-nth 0) returns the first node, | 160 Thus, (ewoc--node-nth 0) returns the first node, |
166 and (ewoc--node-nth -1) returns the last node." | 161 and (ewoc--node-nth -1) returns the last node." |
162 ;; Presuming a node is ":type vector", starting with `left' and `right': | |
167 ;; Branch 0 ("follow left pointer") is used when n is negative. | 163 ;; Branch 0 ("follow left pointer") is used when n is negative. |
168 ;; Branch 1 ("follow right pointer") is used otherwise. | 164 ;; Branch 1 ("follow right pointer") is used otherwise. |
169 (let* ((branch (if (< n 0) 0 1)) | 165 (let* ((branch (if (< n 0) 0 1)) |
170 (node (ewoc--node-branch ewoc--current-dll branch))) | 166 (node (aref ewoc--current-dll branch))) |
171 (if (< n 0) (setq n (- -1 n))) | 167 (if (< n 0) (setq n (- -1 n))) |
172 (while (and (not (eq ewoc--current-dll node)) (> n 0)) | 168 (while (and (not (eq ewoc--current-dll node)) (> n 0)) |
173 (setq node (ewoc--node-branch node branch)) | 169 (setq node (aref node branch)) |
174 (setq n (1- n))) | 170 (setq n (1- n))) |
175 (unless (eq ewoc--current-dll node) node))) | 171 (unless (eq ewoc--current-dll node) node))) |
176 | 172 |
177 (defun ewoc-location (node) | 173 (defun ewoc-location (node) |
178 "Return the start location of NODE." | 174 "Return the start location of NODE." |