[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 9827131 016/154: Fixed unwrapped rank-functio
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 9827131 016/154: Fixed unwrapped rank-function bug in dictree--query |
Date: |
Mon, 14 Dec 2020 12:21:35 -0500 (EST) |
branch: externals/dict-tree
commit 982713159e54ed53ab71cec44e5be9983dff2979
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>
Fixed unwrapped rank-function bug in dictree--query
---
dict-tree.el | 68 ++++++++++++++++++++++++++++++++----------------------------
1 file changed, 36 insertions(+), 32 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index ae6f5fb..e744da1 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -1621,10 +1621,9 @@ Returns nil if the stack is empty."
;; Advanced queries
(defun dictree--query (query-type dict arg
- &optional
- rankfun maxnum reverse no-cache filter)
+ &optional rank-function maxnum reverse no-cache filter)
;; Return results of QUERY-TYPE (currently, only 'complete is implemented)
- ;; on DICT. If RANKFUN is non-nil, return results ordered accordingly.
+ ;; on DICT. If RANK-FUNCTION is non-nil, return results ordered accordingly.
;; wrap DICT in a list if necessary
(when (dictree-p dict) (setq dict (list dict)))
@@ -1633,24 +1632,26 @@ Returns nil if the stack is empty."
;; map over all dictionaries in list
(dolist (dic dict)
(cond
- ;; If FILTER or custom RANKFUN was specified, look in trie since we
don't
- ;; cache custom searches. We pass a slightly redefined filter to
- ;; `trie-complete' to deal with data wrapping.
+ ;; If FILTER or custom RANK-FUNCTION was specified, look in trie since
+ ;; we don't cache custom searches. We pass a slightly redefined filter
+ ;; to `trie-complete' to deal with data wrapping.
((or filter
- (and rankfun (not (eq rankfun (dictree-rank-function dic)))))
+ (and rank-function
+ (not (eq rank-function (dictree-rank-function dic)))))
(setq cmpl
(dictree--do-query
- query-type dic arg rankfun maxnum reverse
+ query-type dic arg rank-function maxnum reverse
(when filter
(eval (macroexpand `(dictree--wrap-filter ,filter)))))))
;; if there's a cached result with enough completions, use it
((and (setq cache
- (if (dictree--query-cacheparam query-type dic rankfun)
+ (if (dictree--query-cacheparam query-type dic
+ rank-function)
(gethash (cons arg reverse)
(dictree--query-cache
- query-type dic rankfun))
+ query-type dic rank-function))
nil))
(or (null (dictree--cache-maxnum cache))
(and maxnum (<= maxnum (dictree--cache-maxnum cache)))))
@@ -1665,32 +1666,34 @@ Returns nil if the stack is empty."
(t
(let (time)
(setq time (float-time))
- (setq cmpl (dictree--do-query query-type
- dic arg rankfun maxnum reverse nil))
+ (setq cmpl (dictree--do-query
+ query-type dic arg rank-function maxnum reverse nil))
(setq time (- (float-time) time))
;; if we took longer than dictionary's completion cache threshold,
;; cache the result
(when (and (not no-cache)
- (dictree--query-cacheparam query-type dic rankfun)
- (or (eq (dictree--query-cacheparam query-type dic rankfun)
+ (dictree--query-cacheparam query-type dic rank-function)
+ (or (eq (dictree--query-cacheparam
+ query-type dic rank-function)
t)
(> time (dictree--query-cacheparam
- query-type dic rankfun))))
+ query-type dic rank-function))))
(setf (dictree-modified dic) t)
(puthash (cons arg reverse)
(dictree--cache-create cmpl maxnum)
- (dictree--query-cache query-type dic rankfun))))))
+ (dictree--query-cache query-type dic rank-function))))))
;; merge new completion into completions list
(setq completions
(dictree--merge
completions cmpl
- (or rankfun
- `(lambda (a b)
- (,(eval (macroexpand
- `(trie-construct-sortfun
- ,(dictree-comparison-function dict))))
- (car a) (car b))))
+ (if rank-function
+ (eval (macroexpand `(dictree--wrap-rankfun ,rank-function)))
+ `(lambda (a b)
+ (,(eval (macroexpand
+ `(trie-construct-sortfun
+ ,(dictree-comparison-function dict))))
+ (car a) (car b))))
nil maxnum))
)
completions))
@@ -1698,19 +1701,20 @@ Returns nil if the stack is empty."
(defun dictree--do-query (query-type dict arg
- &optional rankfun maxnum reverse filter)
+ &optional rank-function maxnum reverse filter)
;; Return first MAXNUM results of running QUERY-TYPE on DICT that satisfy
- ;; FILTER, ordered according to RANKFUN (defaulting to "lexical" order).
+ ;; FILTER, ordered according to RANK-FUNCTION (defaulting to "lexical"
+ ;; order).
;; for a meta-dict, use a dictree-stack
(if (dictree--meta-dict-p dict)
(let ((stack (funcall (dictree--query-stackfun query-type)
dict arg reverse))
- (heap (when rankfun
+ (heap (when rank-function
(heap-create ; heap order is inverse of rank order
(if reverse
- rankfun
- (lambda (a b) (not (funcall rankfun a b))))
+ rank-function
+ (lambda (a b) (not (funcall rank-function a b))))
(1+ maxnum))))
(i 0) cmpl completions)
;; pop MAXNUM completions from the stack
@@ -1718,11 +1722,11 @@ Returns nil if the stack is empty."
(setq cmpl (dictree-stack-pop stack)))
;; check completion passes FILTER
(when (or (null filter) (funcall filter cmpl))
- (if rankfun
+ (if rank-function
(heap-add heap cmpl) ; for ranked query, add to heap
(push cmpl completions)) ; for lexical query, add to list
(incf i)))
- (if (null rankfun)
+ (if (null rank-function)
;; for lexical query, reverse and return completion list (we built
;; it backwards)
(nreverse completions)
@@ -1739,8 +1743,8 @@ Returns nil if the stack is empty."
;; Note: could use a dictree-stack here too - would it be more efficient?
(funcall (dictree--query-triefun query-type)
(dictree--trie dict) arg
- (when rankfun
- (eval (macroexpand `(dictree--wrap-rankfun ,rankfun))))
+ (when rank-function
+ (eval (macroexpand `(dictree--wrap-rankfun ,rank-function))))
maxnum reverse filter)))
@@ -1753,7 +1757,7 @@ Returns nil if the stack is empty."
rank-function maxnum reverse no-cache filter)
"Return an alist containing all completions of sequence PREFIX
from dictionary DICT, along with their associated data, sorted
-according to RANKFUN (defaulting to \"lexical\" order, i.e. the
+according to RANK-FUNCTION (defaulting to \"lexical\" order, i.e. the
order defined by the dictionary's comparison function,
cf. `dictree-create'). If no completions are found, return nil.
- [elpa] branch externals/dict-tree created (now 9242ff7), Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree ae0dc0e 001/154: Version 0.10 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d86829b 007/154: Fixed bugs in predictive's auto-learn and which dict mode features., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 47f8163 010/154: Made saving dictionaries to compiled or uncomiled forms a customization option., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9e6d0f2 017/154: Fixed bug when deleting non-existent entries., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4cd369d 027/154: Avoid breaking setf abstraction in dictree--wrap-insfun., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9827131 016/154: Fixed unwrapped rank-function bug in dictree--query,
Stefan Monnier <=
- [elpa] externals/dict-tree 87bb7e8 019/154: Allow custom write and load functions when saving and dumping dictionaries;, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 2978fc7 024/154: ...and already a bug-fix to the new cache updating code, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 7d9b258 033/154: Improved handling of dictionary file names in dictree-load, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f46da76 008/154: Minor bug fixes., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 405d11b 023/154: Implemented the other cache and cache-update policies, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 57d59eb 021/154: Bug-fixes to predictive-auto-learn and read-dict., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 76140ec 026/154: Converted function wrapping macros into functions, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9120845 032/154: Make weird variable names used to avoid dynamic scoping bugs more consistent, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 6c21fcb 038/154: Fix dictree--query and dictree-complete to return results in correct format, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8a575f6 039/154: Added new trie functions to dictree--create-custom., Stefan Monnier, 2020/12/14