[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/trie 4001f61 097/111: Fix corresponding bug in trie-fuz
From: |
Stefan Monnier |
Subject: |
[elpa] externals/trie 4001f61 097/111: Fix corresponding bug in trie-fuzzy-complete-stack. |
Date: |
Mon, 14 Dec 2020 11:35:28 -0500 (EST) |
branch: externals/trie
commit 4001f612398b1bde3d3bb8a1fb4f2ebd85a474ab
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Fix corresponding bug in trie-fuzzy-complete-stack.
---
trie.el | 87 ++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 45 insertions(+), 42 deletions(-)
diff --git a/trie.el b/trie.el
index a53cb70..04b0760 100644
--- a/trie.el
+++ b/trie.el
@@ -2476,10 +2476,10 @@ the form:
((KEY DIST PFXLEN) . DATA)
-where KEY is a key from the trie, DIST is its Lewenstein
-distances from PREFIX, and DATA is its associated data. RANKFUN
-should return non-nil if first argument is ranked strictly higher
-than the second, nil otherwise.
+where KEY is a key from the trie, DIST is its Lewenstein distance
+from PREFIX, and DATA is its associated data. RANKFUN should
+return non-nil if first argument is ranked strictly higher than
+the second, nil otherwise.
The FILTER argument sets a filter function for the matches. If
@@ -2660,9 +2660,9 @@ give meaningful results; use `trie-complete-stack'
instead.)"
(while (and node
(not (and (trie--node-data-p node)
(or (eq distance t) ; completing a prefix
- (<= (aref row (1- (length row))) distance))
+ (<= pfxcost distance))
)))
- ;; drop data nodes whose SEQ is greater than DISTANCE
+ ;; drop data nodes whose prefix cost is greater than DISTANCE
(unless (trie--node-data-p node)
;; build next row of Lewenstein table
(setq row (Lewenstein--next-row
@@ -2670,46 +2670,49 @@ give meaningful results; use `trie-complete-stack'
instead.)"
seq (trie--seq-append seq (trie--node-split node)))
(when (<= (aref row (1- (length row))) pfxcost)
(setq pfxcost (aref row (1- (length row)))
- pfxlen (length seq)))
-
- (cond
- ;; if we're completing a prefix, always push next node onto stack
- ((eq distance t)
- (push
- (list seq
- (funcall stack-createfun
- (trie--node-subtree node) reverse)
- prefix t row pfxcost pfxlen)
- store))
-
- ;; if we've found a prefix within DISTANCE of PREFIX, then
- ;; everything below node belongs on stack
- ((<= (aref row (1- (length row))) distance)
- (push
- (list seq
- (funcall stack-createfun
- (trie--node-subtree node) reverse)
- ;; t in distance slot indicates completing
- prefix t row pfxcost pfxlen)
- store))
-
- ;; if some row entry for non-data node is <= DISTANCE, push node
- ;; onto stack
- ((<= (apply #'min (append row nil)) distance)
- (push
- (list seq
- (funcall stack-createfun
- (trie--node-subtree node) reverse)
- prefix distance row pfxcost pfxlen)
- store))))
+ pfxlen (length seq)))
+
+ (let ((min (apply #'min (append row nil))))
+ (cond
+ ;; if we're completing a prefix, always push next node onto stack
+ ((eq distance t)
+ (push
+ (list seq
+ (funcall stack-createfun
+ (trie--node-subtree node) reverse)
+ prefix t row pfxcost pfxlen)
+ store))
+
+ ;; if there's a prefix of current SEQ within DISTANCE of PREFIX
+ ;; and no ROW entry is less than this, we're not going to find
+ ;; a better prefix, so everything below node belongs on stack
+ ((and (<= pfxcost distance) (> min pfxcost))
+ (push
+ (list seq
+ (funcall stack-createfun
+ (trie--node-subtree node) reverse)
+ ;; t in distance slot indicates completing
+ prefix t row pfxcost pfxlen)
+ store))
+
+ ;; if some row entry for non-data node is <= DISTANCE, push node
+ ;; onto stack
+ ((<= min distance)
+ (push
+ (list seq
+ (funcall stack-createfun
+ (trie--node-subtree node) reverse)
+ prefix distance row pfxcost pfxlen)
+ store))
+ )))
;; get next node from stack
(when (setq node (car store))
- (setq seq (nth 0 node)
- prefix (nth 2 node)
+ (setq seq (nth 0 node)
+ prefix (nth 2 node)
distance (nth 3 node)
- row (nth 4 node)
- node (funcall stack-popfun (nth 1 node)))
+ row (nth 4 node)
+ node (funcall stack-popfun (nth 1 node)))
;; drop head of stack if nodes are exhausted
(when (funcall stack-emptyfun (nth 1 (car store)))
(setq store (cdr store)))))
- [elpa] externals/trie d99fb00 055/111: Simplified advice-based edebug pretty-printing of tries and dictionaries., (continued)
- [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
- [elpa] externals/trie 5e8e73f 081/111: Fix data wrapping handling in fuzzy query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 2a9d7ec 099/111: Port efficiency improvements to trie-fuzzy-match., Stefan Monnier, 2020/12/14
- [elpa] externals/trie a2554d6 094/111: Fix function symbol quoting., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c6ddbb9 096/111: Bump version numbers., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 94a1a86 087/111: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 4001f61 097/111: Fix corresponding bug in trie-fuzzy-complete-stack.,
Stefan Monnier <=
- [elpa] externals/trie 91d299c 104/111: Pretty-print trie nodes in edebug., Stefan Monnier, 2020/12/14
- [elpa] externals/trie fc9b218 032/111: Removed support for non-terminal * wildcards, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 5a064c0 092/111: Fix bug in trie-delete return value., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 9f49d95 086/111: Implement iterator generators on collection data structures., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 2957aec 103/111: Fix bugs in trie-fuzzy-match/complete., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 3a734c3 077/111: Implement trie-fuzzy-match and trie-fuzzy-complete functions., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 9259d51 088/111: Improve edebug pretty-printing., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 81899c0 110/111: * packages/trie/trie.el (trie--if-lexical-binding): Simplify, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 31c4ac2 024/111: Implemented trie-wildcard-stacks!, Stefan Monnier, 2020/12/14
- [elpa] externals/trie a438b01 090/111: Fix bugs in lexical binding support(?), Stefan Monnier, 2020/12/14