Function: avy-tree
avy-tree is a byte-compiled function defined in avy.el.
Signature
(avy-tree LST KEYS)
Documentation
Coerce LST into a balanced tree.
The degree of the tree is the length of KEYS. KEYS are placed appropriately on internal nodes.
Source Code
;; Defined in ~/.emacs.d/elpa/avy-20241101.1357/avy.el
(defun avy-tree (lst keys)
"Coerce LST into a balanced tree.
The degree of the tree is the length of KEYS.
KEYS are placed appropriately on internal nodes."
(let* ((len (length keys))
(order-fn (cdr (assq avy-command avy-orders-alist)))
(lst (if order-fn
(cl-sort lst #'< :key order-fn)
lst)))
(cl-labels
((rd (ls)
(let ((ln (length ls)))
(if (< ln len)
(cl-pairlis keys
(mapcar (lambda (x) (cons 'leaf x)) ls))
(let ((ks (copy-sequence keys))
res)
(dolist (s (avy-subdiv ln len))
(push (cons (pop ks)
(if (eq s 1)
(cons 'leaf (pop ls))
(rd (avy-multipop ls s))))
res))
(nreverse res))))))
(rd lst))))