Function: rcirc-make-trees
rcirc-make-trees is a byte-compiled function defined in rcirc.el.gz.
Signature
(rcirc-make-trees PAIRS)
Documentation
Generate tree prefix tree of buffer names.
PAIRS is a list of (TARGET . BUFFER) entries. The resulting tree is a list of (CHAR . CHILDREN) cons-cells, where CHAR is the leading character and CHILDREN is either BUFFER when a unique prefix could be found or another tree if it shares the same prefix with another element in PAIRS.
Source Code
;; Defined in /usr/src/emacs/lisp/net/rcirc.el.gz
(defun rcirc-make-trees (pairs)
"Generate tree prefix tree of buffer names.
PAIRS is a list of (TARGET . BUFFER) entries. The resulting tree
is a list of (CHAR . CHILDREN) cons-cells, where CHAR is the
leading character and CHILDREN is either BUFFER when a unique
prefix could be found or another tree if it shares the same
prefix with another element in PAIRS."
(let (alist)
(mapc (lambda (pair)
(if (consp pair)
(let* ((str (car pair))
(data (cdr pair))
(char (unless (zerop (length str))
(aref str 0)))
(rest (unless (zerop (length str))
(substring str 1)))
(part (if char (assq char alist))))
(if part
;; existing partition
(setcdr part (cons (cons rest data) (cdr part)))
;; new partition
(setq alist (cons (if char
(list char (cons rest data))
data)
alist))))
(setq alist (cons pair alist))))
pairs)
;; recurse into cdrs of alist
(mapc (lambda (x)
(when (and (listp x) (listp (cadr x)))
(setcdr x (if (> (length (cdr x)) 1)
(rcirc-make-trees (cdr x))
(setcdr x (list (cdadr x)))))))
alist)))