[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree f0396a0 087/154: Fixed bugs in synchronisatio
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree f0396a0 087/154: Fixed bugs in synchronisation of regexp query caches. |
Date: |
Mon, 14 Dec 2020 12:21:50 -0500 (EST) |
branch: externals/dict-tree
commit f0396a0c0cc9180f8f950ef690f8f8af4daefe4e
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Fixed bugs in synchronisation of regexp query caches.
Renamed dictree--synchronise-[ranked-]query-cache to
dictree--synchronise-[ranked-]completion-cache, and created separate
dictree--synchronise-[ranked-]regexp-cache functions to handle regexp query
caches.
---
dict-tree.el | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 142 insertions(+), 15 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index 2c2df2d..e8b7545 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -52,6 +52,7 @@
;;; Change log:
+;;
;; Version 0.12.4
;; * minor bug-fix to `dictree--edebug-pretty-print' to print "nil"
;; instead of "()"
@@ -67,6 +68,14 @@
;; * fixed implementation of 'both cache policy
;; * fixed bug in `read-dict' preventing completion on dictionary files
;; in `load-path'
+;; * fixed bugs in synchronisation of regexp query caches, renaming
+;; `dictree--synchronise-query-cache' and
+;; `dictree--synchronise-ranked-query-cache' to
+;; `dictree--synchronise-completion-cache' and
+;; `dictree--synchronise-ranked-completion-cache', and creating
+;; separate `dictree--synchronise-regexp-cache' and
+;; `dictree--synchronise-ranked-regep-cache' functions to handle
+;; regexp query caches
;;
;; Version 0.12.3
;; * bug-fix in `dictree--edebug-pretty-print'
@@ -334,6 +343,7 @@ If START or END is negative, it counts from the end."
(cons (car b) (dictree--cell-data (cdr b))))))
(defun dictree--wrap-combfun (combfun) ; INTERNAL USE ONLY
+ ;; return wrapped combfun to deal with data wrapping
`(lambda (cell1 cell2)
(cons (,combfun (dictree--cell-data cell1)
(dictree--cell-data cell2))
@@ -1289,8 +1299,8 @@ PREFIX is a prefix of STR."
(cond
;; if updating dirty cache entries...
((eq (dictree-cache-update-policy dict) 'synchronize)
- (dictree--synchronize-query-cache
- dict cache cache-entry arg reverse key newdata deleted))
+ (dictree--synchronize-completion-cache
+ dict cache-entry arg reverse key newdata deleted))
;; if deleting dirty cache entries...
(t (remhash (cons arg reverse) cache)))))
cache))
@@ -1307,8 +1317,8 @@ PREFIX is a prefix of STR."
(cond
;; if updating dirty cache entries...
((eq (dictree-cache-update-policy dict) 'synchronize)
- (dictree--synchronize-ranked-query-cache
- dict cache cache-entry arg reverse key newdata deleted))
+ (dictree--synchronize-ranked-completion-cache
+ dict cache-entry arg reverse key newdata deleted))
;; if deleting dirty cache entries...
(t (remhash (cons arg reverse) cache)))))
cache))
@@ -1326,8 +1336,8 @@ PREFIX is a prefix of STR."
(cond
;; if updating dirty cache entries...
((eq (dictree-cache-update-policy dict) 'synchronize)
- (dictree--synchronize-query-cache
- dict cache cache-entry arg reverse key newdata deleted))
+ (dictree--synchronize-regexp-cache
+ dict cache-entry arg reverse key newdata deleted))
;; if deleting dirty cache entries...
(t (remhash (cons arg reverse) cache)))))
cache))
@@ -1345,8 +1355,8 @@ PREFIX is a prefix of STR."
(cond
;; if updating dirty cache entries...
((eq (dictree-cache-update-policy dict) 'synchronize)
- (dictree--synchronize-ranked-query-cache
- dict cache cache-entry arg reverse key newdata deleted))
+ (dictree--synchronize-ranked-regexp-cache
+ dict cache-entry arg reverse key newdata deleted))
;; if deleting dirty cache entries...
(t (remhash (cons arg reverse) cache)))))
cache))
@@ -1354,9 +1364,9 @@ PREFIX is a prefix of STR."
-(defun dictree--synchronize-query-cache
- (dict cache cache-entry arg reverse key newdata deleted)
- ;; Synchronize DICT's query CACHE CACHE-ENTRY for ARG and REVERSE, for
+(defun dictree--synchronize-completion-cache
+ (dict cache-entry arg reverse key newdata deleted)
+ ;; Synchronize DICT's completion CACHE-ENTRY for ARG and REVERSE, for
;; a KEY whose data was either updated to NEWDATA or DELETED.
(let* ((completions (dictree--cache-results cache-entry))
(maxnum (dictree--cache-maxnum cache-entry))
@@ -1392,14 +1402,15 @@ PREFIX is a prefix of STR."
-(defun dictree--synchronize-ranked-query-cache
- (dict cache cache-entry arg reverse key newdata deleted)
- ;; Synchronize DICT's ranked query CACHE CACHE-ENTRY for ARG and
+(defun dictree--synchronize-ranked-completion-cache
+ (dict cache-entry arg reverse key newdata deleted)
+ ;; Synchronize DICT's ranked completion CACHE-ENTRY for ARG and
;; REVERSE, for a KEY whose data was either updated to NEWDATA or
;; DELETED.
(let* ((completions (dictree--cache-results cache-entry))
(maxnum (dictree--cache-maxnum cache-entry))
- (cmpl (assoc key completions)))
+ (cmpl (assoc key completions))
+ (cache (dictree--complete-ranked-cache dict)))
;; if key was...
(cond
;; deleted and in cached result: remove cache entry and re-run the
@@ -1433,6 +1444,122 @@ PREFIX is a prefix of STR."
)))
+(defun dictree--synchronize-regexp-cache
+ (dict cache-entry arg reverse key newdata deleted)
+ ;; Synchronize DICT's completion CACHE-ENTRY for ARG and REVERSE, for
+ ;; a KEY whose data was either updated to NEWDATA or DELETED.
+ (let* ((completions (dictree--cache-results cache-entry))
+ (maxnum (dictree--cache-maxnum cache-entry))
+ group-data
+ (cmpl (catch 'found
+ (dolist (c completions)
+ (if (and (listp (car c))
+ (or (stringp (caar c))
+ (vectorp (caar c))
+ (listp (caar c))))
+ (when (equal key (caar c)) (throw 'found c))
+ (when (equal key (car c)) (throw 'found c)))))))
+ ;; if key was...
+ (cond
+ ;; deleted and in cached result: remove cache entry and re-run the
+ ;; same completion to update the cache
+ ((and deleted cmpl)
+ (remhash (cons arg reverse) (dictree-complete-cache dict))
+ (dictree-regexp-search dict arg nil maxnum reverse))
+ ;; modified and not in cached result: merge it into the completion
+ ;; list, retaining only the first maxnum
+ ((and (not deleted) (not cmpl))
+ (save-match-data
+ (set-match-data nil)
+ (tNFA-regexp-match arg key
+ :test (dictree--comparison-function dict))
+ (when (setq group-data (nthcdr 2 (match-data)))
+ (setq key (cons key group-data))))
+ (dictree--cache-set-completions
+ cache-entry
+ (dictree--merge
+ (list (cons key newdata)) completions
+ `(lambda (a b)
+ (,(trie-construct-sortfun (dictree-comparison-function dict))
+ ,(if group-data '(caar a) '(car a))
+ ,(if group-data '(caar b) '(car b))))
+ (when (dictree--meta-dict-p dict)
+ (dictree--meta-dict-combfun dict))
+ maxnum)))
+ ;; modified and in the cached result: update the associated data if
+ ;; dict is a meta-dictionary (this is done automatically for a
+ ;; normal dict)
+ ((and (not deleted) cmpl (dictree--meta-dict-p dict))
+ (setcdr cmpl newdata))
+ ;; deleted and not in cached result: requires no action
+ )))
+
+
+
+(defun dictree--synchronize-ranked-regexp-cache
+ (dict cache-entry arg reverse key newdata deleted)
+ ;; Synchronize DICT's ranked regexp CACHE-ENTRY for ARG and REVERSE,
+ ;; for a KEY whose data was either updated to NEWDATA or DELETED.
+ (let ((completions (dictree--cache-results cache-entry))
+ (maxnum (dictree--cache-maxnum cache-entry))
+ (cache (dictree--regexp-ranked-cache dict))
+ cmpl group-data)
+ (setq group-data (and (listp (caar completions))
+ (or (stringp (caar (car completions)))
+ (vectorp (caar (car completions)))
+ (listp (caar (car completions))))))
+ (setq cmpl
+ (catch 'found
+ (dolist (c completions)
+ (if group-data
+ (when (equal key (caar c)) (throw 'found c))
+ (when (equal key (car c)) (throw 'found c))))))
+ ;; if key was...
+ (cond
+ ;; deleted and in cached result: remove cache entry and re-run the
+ ;; same query to update the cache
+ ((and deleted cmpl)
+ (remhash (cons arg reverse) cache)
+ (dictree-regexp-search dict arg 'ranked maxnum reverse))
+ ;; modified and not in cached result: merge it into the completion
+ ;; list, retaining only the first maxnum
+ ((and (not deleted) (not cmpl))
+ (save-match-data
+ (set-match-data nil)
+ (tNFA-regexp-match arg key
+ :test (dictree--comparison-function dict))
+ (when (setq group-data (nthcdr 2 (match-data)))
+ (setq key (cons key group-data))))
+ (dictree--cache-set-completions
+ cache-entry
+ (dictree--merge
+ (list (cons key newdata)) completions
+ (dictree-rankfun dict)
+ (when (dictree--meta-dict-p dict)
+ (dictree--meta-dict-combfun dict))
+ maxnum)))
+ ;; modified and in the cached result: update the associated data if
+ ;; dict is a meta-dictionary (this is done automatically for a
+ ;; normal dict), re-sort, and if key is now at end of list re-run
+ ;; the same query to update the cache
+ ((and (not deleted) cmpl)
+ (when (dictree--meta-dict-p dict) (setcdr cmpl newdata))
+ (dictree--cache-set-completions
+ cache-entry
+ (sort completions
+ (if group-data
+ `(lambda (a b)
+ (,(dictree-rankfun dict)
+ (cons (caar a) (cdr a))
+ (cons (caar b) (cdr b))))
+ (dictree-rankfun dict))))
+ (when (equal key (car (last completions)))
+ (remhash (cons arg reverse) cache)
+ (dictree-complete dict arg 'ranked maxnum reverse)))
+ ;; deleted and not in cached result: requires no action
+ )))
+
+
(defun dictree-clear-caches (dict)
"Clear all DICT's query caches."
(interactive (list (read-dict "Dictionary: ")))
- [elpa] externals/dict-tree 1e5b3f6 130/154: Fix bug in dictree--wrap-fuzzy-rankfun wrapping., (continued)
- [elpa] externals/dict-tree 1e5b3f6 130/154: Fix bug in dictree--wrap-fuzzy-rankfun wrapping., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 6544152 139/154: Fix bug causing dictree--do-query to fail to use cached results., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9242ff7 154/154: * dict-tree/dict-tree.el: Fix typo in Package-Requires., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1d096b1 141/154: Myriad bug fixes and code refactoring in new fuzzy and ngram completion., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 572c746 149/154: Fix byte-compilation errors and warnings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3ddde93 143/154: Switch to keyword arguments for trie/dictree query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1030ae2 071/154: Require advice when compiling, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 7a51b21 083/154: Fixed dictree--update-cache to work for lists of prefixes., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 50ae73e 085/154: Fixed bug in Read-Dict preventing completion on dict files in load-path., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree bc5724e 080/154: Minor bug-fixes to [trie/dict-tree]--edebug-pretty-print, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f0396a0 087/154: Fixed bugs in synchronisation of regexp query caches.,
Stefan Monnier <=
- [elpa] externals/dict-tree 18ede82 089/154: Fixed minor spelling errors in docstrings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree a9344ec 093/154: Updated Package-Version, Package-Requires, and Keywords package headers., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4722fcb 100/154: Modified read-dict to return dictionary name instead of dictionary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d325841 009/154: Dictionaries are now saved in both compiled and uncompiled forms., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 753904c 034/154: Added functions for pushing things onto dictree and trie stacks, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree b3eb0f1 031/154: Bug-fix to dictree-insert, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 0774b51 048/154: Added support for wildcard searches, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 06f5039 055/154: Bug-fix to 'resultfun' feature in dictree--query and dictree--do-query, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 9e9d7e9 056/154: Added dictree-clear-caches for doing the obvious, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 32bb6e2 061/154: Replaced wildcard searches with more powerful and efficient regexp searches., Stefan Monnier, 2020/12/14