[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree c737d3a 134/154: Make use of new trie-fuzzy-c
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree c737d3a 134/154: Make use of new trie-fuzzy-complete facilities. |
Date: |
Mon, 14 Dec 2020 12:22:01 -0500 (EST) |
branch: externals/dict-tree
commit c737d3adfb8be89bada3801d027d781497979662
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Make use of new trie-fuzzy-complete facilities.
---
dict-tree.el | 137 ++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 88 insertions(+), 49 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index 6cf4021..0ce595c 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -2603,46 +2603,52 @@ to its constituent dicts."
;; AUXARGS list, if any) using TRIEFUN or STACKFUN that satisfy FILTER,
;; ordered according to RANKFUN (defaulting to "lexicographic" order).
- ;; for a meta-dict, use a dictree-stack
- (if (dictree--meta-dict-p dict)
- (let ((stack (apply stackfun
- (append (list dict arg) auxargs (list reverse))))
- (heap (when rankfun
- (heap-create ; heap order is inverse of rank order
- (if reverse
- rankfun
- (lambda (a b)
- (not (funcall rankfun a b))))
- (1+ maxnum))))
- (i 0) res results)
- ;; pop MAXNUM results from the stack
- (while (and (or (null maxnum) (< i maxnum))
- (setq res (dictree--stack-pop stack)))
- ;; check result passes FILTER
- (when (or (null filter) (funcall filter res))
- (if rankfun
- (heap-add heap res) ; for ranked query, add to heap
- (push res results)) ; for lexicographic query, add to list
- (incf i)))
- (if (null rankfun)
- ;; for lexicographic query, reverse and return result list (we
- ;; built it backwards)
- (nreverse results)
- ;; for ranked query, pass rest of results through heap
- (while (setq res (dictree--stack-pop stack))
- (heap-add heap res)
- (heap-delete-root heap))
- ;; extract results from heap
- (while (setq res (heap-delete-root heap))
- (push res results))
- results)) ; return result list
-
- ;; for a normal dict, call corresponding trie function on dict's
- ;; trie. Note: could use a dictree-stack here too - would it be more
- ;; efficient?
- (apply triefun
- (append (list (dictree--trie dict) arg) auxargs
- (list rankfun maxnum reverse filter)))))
+ (if (dictree--p dict)
+ ;; for a normal dict, call corresponding trie function on dict's
+ ;; trie. Note: could use a dictree-stack here too - would it be more
+ ;; efficient?
+ (apply triefun
+ (append (list (dictree--trie dict) arg) auxargs
+ (list rankfun maxnum reverse filter)))
+
+ ;; `dictree-fuzzy-complete' rankfun can be a cons cell with rankfun in cdr
+ (when (and (eq stackfun #'dictree-fuzzy-complete-stack)
+ (eq (car-safe rankfun) t))
+ (setq rankfun (cdr rankfun)))
+
+ ;; for a meta-dict, use a dictree-stack
+ (let ((stack (apply stackfun
+ (append (list dict arg) auxargs (list reverse))))
+ (heap (when rankfun
+ (heap-create ; heap order is inverse of rank order
+ (if reverse
+ rankfun
+ (lambda (a b)
+ (not (funcall rankfun a b))))
+ (1+ maxnum))))
+ (i 0) res results)
+ ;; pop MAXNUM results from the stack
+ (while (and (or (null maxnum) (< i maxnum))
+ (setq res (dictree--stack-pop stack)))
+ ;; check result passes FILTER
+ (when (or (null filter) (funcall filter res))
+ (if rankfun
+ (heap-add heap res) ; for ranked query, add to heap
+ (push res results)) ; for lexicographic query, add to list
+ (incf i)))
+ (if (null rankfun)
+ ;; for lexicographic query, reverse and return result list (we
+ ;; built it backwards)
+ (nreverse results)
+ ;; for ranked query, pass rest of results through heap
+ (while (setq res (dictree--stack-pop stack))
+ (heap-add heap res)
+ (heap-delete-root heap))
+ ;; extract results from heap
+ (while (setq res (heap-delete-root heap))
+ (push res results))
+ results)) ; return result list
+ ))
@@ -2927,10 +2933,17 @@ of the default key-dist-data list."
(when rank-function
(cond
((eq rank-function 'distance) t)
- ((functionp rank-function) (dictree--wrap-fuzzy-rankfun rank-function))
((eq rank-function t)
(dictree--wrap-fuzzy-rankfun
- (dictree-rank-function (if (listp dict) (car dict) dict))))))
+ (dictree-rank-function (if (listp dict) (car dict) dict))))
+ ((and (eq (car-safe rank-function) t)
+ (eq (cdr-safe rank-function) 'ranked))
+ (cons t (dictree--wrap-rankfun
+ (dictree-rank-function (if (listp dict) (car dict) dict)))))
+ ((eq (car-safe rank-function) t)
+ (cons t (dictree--wrap-fuzzy-rankfun (cdr rank-function))))
+ ((functionp rank-function) (dictree--wrap-fuzzy-rankfun rank-function))
+ ))
maxnum reverse filter resultfun))
@@ -2969,11 +2982,30 @@ DISTANCE must be an integer, and specifies the maximum
Lewenstein
distance \(edit distances\) of prefixes from PREFIX.
-If optional argument RANK-FUNCTION is the symbol `distance', the
-matches are sorted by increasing Lewenstein distance of their
-prefix \(with same-distance prefixes ordered
-lexicographically\). If it is t, the matches are sorted according
-to the dictionary's rank-function (see `dictree-create').
+If optional argument RANK-FUNCTION is the symbol `ranked', the
+matches are sorted according to the dictionary's
+rank-function (see `dictree-create').
+
+If RANK-FUNCTION is t, the matches are sorted by increasing
+Lewenstein distance of their prefix, with same-distance prefixes
+ordered lexicographically.
+
+If RANK-FUNCTION is a cons cell of the form
+
+ (t . RANKFUN)
+
+then matches are again ordered by increasing Lewenstein distance
+of their prefix, but with same-distance prefixes ordered by
+RANKFUN. If RANKFUN is the symbol `ranked', same-distance
+prefixes are ordered by the dictionary's rank-function (see
+`dictree-create'). Otherwise, RANKFUN should take two arguments,
+both of the form
+
+ (KEY . DATA)
+
+where KEY is a key from the trie and DATA is its associated data.
+RANKFUN should return non-nil if first argument is ranked
+strictly higher than the second, nil otherwise.
Any other non-nil value of RANK-FUNCTION should be a function
that accepts two arguments, both of the form:
@@ -3016,10 +3048,17 @@ of the default key-dist-data list."
(when rank-function
(cond
((eq rank-function 'distance) t)
- ((functionp rank-function) (dictree--wrap-fuzzy-rankfun rank-function))
((eq rank-function t)
(dictree--wrap-fuzzy-rankfun
- (dictree-rank-function (if (listp dict) (car dict) dict))))))
+ (dictree-rank-function (if (listp dict) (car dict) dict))))
+ ((and (eq (car-safe rank-function) t)
+ (eq (cdr-safe rank-function) 'ranked))
+ (cons t (dictree--wrap-rankfun
+ (dictree-rank-function (if (listp dict) (car dict) dict)))))
+ ((eq (car-safe rank-function) t)
+ (cons t (dictree--wrap-fuzzy-rankfun (cdr rank-function))))
+ ((functionp rank-function) (dictree--wrap-fuzzy-rankfun rank-function))
+ ))
maxnum reverse filter resultfun))
- [elpa] externals/dict-tree 8d8ce4f 120/154: Print dict-tree cache sizes in edebug., (continued)
- [elpa] externals/dict-tree 8d8ce4f 120/154: Print dict-tree cache sizes in edebug., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 84b23ec 112/154: Implement trie-fuzzy-match and trie-fuzzy-complete functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5321c25 113/154: Implement fuzzy match and completion on dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d0e339d 117/154: Don't wrap rank and filter functions for regexp and fuzzy queries., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a11f2a5 115/154: Update predictive mode to new dictree-create function interface., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 217c9d2 119/154: Updated Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 95d6a5a 127/154: Mention iterator generators in Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d84725e 124/154: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f47d49c 137/154: Bug fixes to meta-dict fuzzy-matching/completing., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 65b94b4 131/154: Bump version numbers., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c737d3a 134/154: Make use of new trie-fuzzy-complete facilities.,
Stefan Monnier <=
- [elpa] externals/dict-tree eec26c3 132/154: Fix trie--construct-Lewenstein-rankfun to new versions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5e2ffac 136/154: Test for lexical binding must be within same file to work reliably., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 22d0e13 140/154: Sort completions by fuzzy dist before ngram length., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 67afade 151/154: Document PFXFILTER argument to query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4299171 150/154: Work around Emacs bug preventing dict-tree caching., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 22d569e 153/154: Improve error reporting when reading dictionary data from dumped file., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f0af36e 148/154: Fix byte-compilation of functions embedded in dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree dd695da 147/154: Display more informative message during writing dict to file., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 45270bc 144/154: Cache all queries, not just those with named function arguments., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1db3424 128/154: Fix quoting of ' in one docstring., Stefan Monnier, 2020/12/14