[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/trie 87d5786 102/111: Allow trie-fuzzy-match/complete t
From: |
Stefan Monnier |
Subject: |
[elpa] externals/trie 87d5786 102/111: Allow trie-fuzzy-match/complete to take lists of multiple prefixes/strings. |
Date: |
Mon, 14 Dec 2020 11:35:29 -0500 (EST) |
branch: externals/trie
commit 87d5786c18c29f39ff2c4f11d6a8d23fa05b118d
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Allow trie-fuzzy-match/complete to take lists of multiple prefixes/strings.
---
trie.el | 175 ++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 104 insertions(+), 71 deletions(-)
diff --git a/trie.el b/trie.el
index e8fdf94..d11653c 100644
--- a/trie.el
+++ b/trie.el
@@ -1607,20 +1607,17 @@ default key-data cons cell."
(trie--comparison-function trie))))))
;; accumulate completions
- (let (node)
(trie--accumulate-results
rankfun maxnum reverse filter resultfun accumulator nil
- (mapc (lambda (pfx)
- (setq node (trie--node-find (trie--root trie) pfx
- (trie--lookupfun trie)))
- (when node
- (trie--mapc
- (lambda (node seq)
- (funcall accumulator seq (trie--node-data node)))
- (trie--mapfun trie) node pfx
- (if maxnum reverse (not reverse)))))
- prefix))
- ))
+ (let (node)
+ (dolist (pfx prefix)
+ (when (setq node (trie--node-find (trie--root trie) pfx
+ (trie--lookupfun trie)))
+ (trie--mapc
+ (lambda (node seq)
+ (funcall accumulator seq (trie--node-data node)))
+ (trie--mapfun trie) node pfx
+ (if maxnum reverse (not reverse))))))))
@@ -2270,28 +2267,41 @@ of the default key-dist-data list."
ranked-by-dist t)))
(when ranked-by-dist (setq stats (make-list (1+ distance) 0)))
+ ;; FIXME: the test for a list of prefixes, below, will fail if the
+ ;; PREFIX sequence is a list, and the elements of PREFIX are
+ ;; themselves lists (there might be no easy way to fully fix
+ ;; this...)
+ (if (or (atom string)
+ (and (listp string) (not (sequencep (car string)))))
+ (setq string (list string))
+ ;; sort list of prefixes if sorting completions lexicographicly
+ (when (null rankfun)
+ (setq string
+ (sort string (trie-construct-sortfun
+ (trie--comparison-function trie))))))
;; accumulate results
(trie--accumulate-results
rankfun maxnum reverse filter resultfun accumulator nil
- (funcall (trie--mapfun trie)
- (lambda (node)
- (trie--do-fuzzy-match
- node
- (apply #'vector (number-sequence 0 (length string)))
- (cond ((stringp string) "") ((listp string) ()) (t []))
- ;; FIXME: Would it pay to replace these arguments with
- ;; dynamically-scoped variables, to save stack space?
- string distance (if maxnum reverse (not reverse))
- (trie--comparison-function trie)
- equalfun
- (trie--lookupfun trie)
- (trie--mapfun trie)
- accumulator
- ranked-by-dist
- (and ranked-by-dist maxnum)
- (and ranked-by-dist maxnum stats)))
- (trie--node-subtree (trie--root trie))
- (if maxnum reverse (not reverse))))))
+ (dolist (str string)
+ (funcall (trie--mapfun trie)
+ (lambda (node)
+ (trie--do-fuzzy-match
+ node
+ (apply #'vector (number-sequence 0 (length str)))
+ (cond ((stringp str) "") ((listp str) ()) (t []))
+ ;; FIXME: Would it pay to replace these arguments with
+ ;; dynamically-scoped variables, to save stack space?
+ str distance (if maxnum reverse (not reverse))
+ (trie--comparison-function trie)
+ equalfun
+ (trie--lookupfun trie)
+ (trie--mapfun trie)
+ accumulator
+ ranked-by-dist
+ (and ranked-by-dist maxnum)
+ (and ranked-by-dist maxnum stats)))
+ (trie--node-subtree (trie--root trie))
+ (if maxnum reverse (not reverse)))))))
(defun trie--do-fuzzy-match (node row seq string distance reverse
@@ -2381,22 +2391,32 @@ STRING."
(defun trie--fuzzy-match-stack-construct-store
(trie string distance &optional reverse)
;; Construct store for fuzzy stack based on TRIE.
- (let ((seq (cond ((stringp string) "") ((listp string) ()) (t [])))
- store)
- (push (list seq
- (funcall (trie--stack-createfun trie)
- (trie--node-subtree (trie--root trie))
- reverse)
- string distance
- (apply #'vector (number-sequence 0 (length string))))
- store)
- (trie--fuzzy-match-stack-repopulate
- store reverse
- (trie--comparison-function trie)
- (trie--lookupfun trie)
- (trie--stack-createfun trie)
- (trie--stack-popfun trie)
- (trie--stack-emptyfun trie))))
+ (let (seq store)
+ (if (or (atom string)
+ (and (listp string)
+ (not (sequencep (car string)))))
+ (setq string (list string))
+ (setq string
+ (sort string
+ (trie-construct-sortfun
+ (trie--comparison-function trie)
+ (not reverse)))))
+ (dolist (str string)
+ (setq seq (cond ((stringp string) "") ((listp string) ()) (t [])))
+ (push (list seq
+ (funcall (trie--stack-createfun trie)
+ (trie--node-subtree (trie--root trie))
+ reverse)
+ str distance
+ (apply #'vector (number-sequence 0 (length string))))
+ store)
+ (trie--fuzzy-match-stack-repopulate
+ store reverse
+ (trie--comparison-function trie)
+ (trie--lookupfun trie)
+ (trie--stack-createfun trie)
+ (trie--stack-popfun trie)
+ (trie--stack-emptyfun trie)))))
(defun trie--fuzzy-match-stack-repopulate
@@ -2581,15 +2601,11 @@ of the default key-dist-pfxlen-data list."
(let ((equalfun (trie--construct-equality-function
(trie--comparison-function trie)))
- (node (trie--root trie))
- length ranked-by-dist stats)
+ length ranked-by-dist stats node)
;; sort out distance argument and find start node
(when (consp distance)
(setq length (car distance)
distance (cdr distance)
- node (trie--node-find (trie--root trie)
- (cl-subseq prefix 0 length)
- (trie--lookupfun trie))
prefix (cl-subseq prefix length)))
(when (setq node (trie--node-subtree node))
@@ -2606,28 +2622,45 @@ of the default key-dist-pfxlen-data list."
ranked-by-dist t)))
(when ranked-by-dist (setq stats (make-list (1+ distance) 0)))
+ ;; FIXME: the test for a list of prefixes, below, will fail if the
+ ;; PREFIX sequence is a list, and the elements of PREFIX are
+ ;; themselves lists (there might be no easy way to fully fix
+ ;; this...)
+ (if (or (atom prefix)
+ (and (listp prefix) (not (sequencep (car prefix)))))
+ (setq prefix (list prefix))
+ ;; sort list of prefixes if sorting completions lexicographicly
+ (when (null rankfun)
+ (setq prefix
+ (sort prefix (trie-construct-sortfun
+ (trie--comparison-function trie))))))
+
;; accumulate results
(trie--accumulate-results
rankfun maxnum reverse filter resultfun accumulator nil
- (funcall (trie--mapfun trie)
- (lambda (node)
- (trie--do-fuzzy-complete
- node
- (apply #'vector (number-sequence 0 (length prefix)))
- (cond ((stringp prefix) "") ((listp prefix) ()) (t []))
- (length prefix) 0
- ;; FIXME: Would it pay to replace these arguments with
- ;; dynamically-scoped variables, to save stack space?
- prefix distance (if maxnum reverse (not reverse))
- (trie--comparison-function trie)
- equalfun
- (trie--lookupfun trie)
- (trie--mapfun trie)
- accumulator
- ranked-by-dist
- (and ranked-by-dist maxnum)
- (and ranked-by-dist maxnum stats)))
- node (if maxnum reverse (not reverse))))
+ (dolist (pfx prefix)
+ (setq node (trie--node-find (trie--root trie)
+ (cl-subseq prefix 0 length)
+ (trie--lookupfun trie)))
+ (funcall (trie--mapfun trie)
+ (lambda (node)
+ (trie--do-fuzzy-complete
+ node
+ (apply #'vector (number-sequence 0 (length prefix)))
+ (cond ((stringp prefix) "") ((listp prefix) ()) (t []))
+ (length prefix) 0
+ ;; FIXME: Would it pay to replace these arguments with
+ ;; dynamically-scoped variables, to save stack
space?
+ pfx distance (if maxnum reverse (not reverse))
+ (trie--comparison-function trie)
+ equalfun
+ (trie--lookupfun trie)
+ (trie--mapfun trie)
+ accumulator
+ ranked-by-dist
+ (and ranked-by-dist maxnum)
+ (and ranked-by-dist maxnum stats)))
+ node (if maxnum reverse (not reverse)))))
)))
- [elpa] externals/trie a8615f7 052/111: Bug-fixes to edebug pretty-print functions., (continued)
- [elpa] externals/trie a8615f7 052/111: Bug-fixes to edebug pretty-print functions., Stefan Monnier, 2020/12/14
- [elpa] externals/trie a1f9faa 044/111: Re-filled to 72 chars/line, for mailing to gnu-emacs-sources list, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 13bb42f 042/111: Updated docstrings for regexp-related functions and others., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c7c9994 015/111: trie--createfun now passed corresponding sequence as an argument, Stefan Monnier, 2020/12/14
- [elpa] externals/trie da9ace9 051/111: More efficient implementations of replacements for CL 'position' function., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 0d17008 037/111: Added nilflag argument to trie-stack functions, Stefan Monnier, 2020/12/14
- [elpa] externals/trie f930fe9 027/111: Documentation updates related to wildcard searches and predictive features that make use of them, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 46369a7 026/111: Added trie-wildcard-match function, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 7823234 095/111: Fix bug in trie-fuzzy-complete that meant it didn't return minimum prefix distance in some cases., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 5fa968c 093/111: Fix byte-compiler warning., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 87d5786 102/111: Allow trie-fuzzy-match/complete to take lists of multiple prefixes/strings.,
Stefan Monnier <=
- [elpa] externals/trie 71f8273 098/111: Significantly improve efficiency of trie-fuzzy-complete., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c2b5e26 105/111: Myriad bug fixes and code refactoring in new fuzzy and ngram completion., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 63da3b1 111/111: * trie.el: Fix header which likely suffered a `M-q` accident, Stefan Monnier, 2020/12/14
- [elpa] externals/trie ff5e05f 040/111: Bumped copyright year, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 2281926 020/111: Minor code reformatting and rearrangement, Stefan Monnier, 2020/12/14
- [elpa] externals/trie d99fb00 055/111: Simplified advice-based edebug pretty-printing of tries and dictionaries., Stefan Monnier, 2020/12/14
- [elpa] externals/trie b4d81bf 064/111: Trivial whitespace tidying., Stefan Monnier, 2020/12/14
- [elpa] externals/trie d45e9d5 062/111: Added autoload cookies., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 1c2790d 038/111: Replaced wildcard searches with more powerful and efficient regexp searches., Stefan Monnier, 2020/12/14
- [elpa] externals/trie bbfecae 085/111: Do lexbind test at compile-time instead of load-time., Stefan Monnier, 2020/12/14