[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 2666377 084/154: Fixed implementation of 'bot
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 2666377 084/154: Fixed implementation of 'both cache policy. |
Date: |
Mon, 14 Dec 2020 12:21:50 -0500 (EST) |
branch: externals/dict-tree
commit 2666377cb8823e5100ad6dc7616e321d4f633c9c
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Fixed implementation of 'both cache policy.
---
dict-tree.el | 66 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 34 insertions(+), 32 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index f0df410..86dad93 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -64,6 +64,7 @@
;; list elements for non-null MAXNUM
;; * fixed `dictree--update-cache', which previously never updated
;; cached results for lists of prefixes in `dictree-complete' queries
+;; * fixed implementation of 'both cache policy
;;
;; Version 0.12.3
;; * bug-fix in `dictree--edebug-pretty-print'
@@ -689,7 +690,9 @@ LOOKUP-CACHE-THRESHOLD value (since those are likely to be
the
slower ones), and caches completions of prefixes that are shorter
than the corresponding CACHE-THRESHOLD (since those are likely to
be the slower ones in that case). The setting 'both requires both
-conditions to be satisfied simultaneously.
+conditions to be satisfied simultaneously. In this case,
+CACHE-THRESHOLD must be a plist with properties :time and :length
+specifying the corresponding cache thresholds.
CACHE-UPDATE-POLICY should be a symbol ('synchronize or 'delete),
which determines how the caches are updated when data is inserted
@@ -1231,6 +1234,28 @@ PREFIX is a prefix of STR."
(throw 'is-prefix t))))))
+(defun dictree--above-cache-threshold-p
+ (time length policy threshold &optional cache-long-keys)
+ ;; Return t if query taking TIME seconds for a key of length LENGTH
+ ;; should be cached according to the cache POLICY and
+ ;; THRESHOLD. Otherwise, return nil. Optional argument CACHE-LONG-KEYS
+ ;; means that keys of length longer than THRESHOLD are to be
+ ;; cached. Default is keys of length shorter than THRESHOLD.
+ (and threshold
+ (or (eq threshold t)
+ (and (eq policy 'time) (>= time threshold))
+ ;; note: we cache lookups of *longer* keys, because those are
+ ;; likely to be slower ones
+ (and (eq policy 'length)
+ (if cache-long-keys
+ (>= length threshold) (<= length threshold)))
+ (and (eq policy 'both)
+ (or (>= time (plist-get threshold :time))
+ (if cache-long-keys
+ (>= length (plist-get threshold :length))
+ (<= length (plist-get threshold :length))))))))
+
+
(defun dictree--update-cache (dict key newdata &optional deleted)
;; Synchronise dictionary DICT's caches, given that the data
;; associated with KEY has been changed to NEWDATA, or KEY has been
@@ -1433,22 +1458,19 @@ Optional argument NILFLAG specifies a value to return
instead of
nil if KEY does not exist in TREE. This allows a non-existent KEY
to be distinguished from an element with a null association. (See
also `dictree-member-p' for testing existence alone.)"
- (let ((data (dictree--lookup dict key nilflag)))
+ (let* ((data (dictree--lookup dict key nilflag)))
(if (eq data nilflag)
nilflag
(dictree--cell-data data))))
-
(defalias 'dictree-lookup 'dictree-member)
-
(defun dictree-member-p (dict key)
"Return t if KEY exists in DICT, nil otherwise."
(let ((flag '(nil)))
(not (eq flag (dictree-member dict key flag)))))
-
(defun dictree--lookup (dict key nilflag)
;; Return association of KEY in DICT, or NILFLAG if KEY does not
;; exist. Does not do any data/meta-data unwrapping
@@ -1473,8 +1495,7 @@ also `dictree-member-p' for testing existence alone.)"
;; skip dictionary if it doesn't contain KEY
(unless (eq newdata newflag)
;; if we haven't found KEY before, we have now!
- (if (eq data flag)
- (setq data newdata)
+ (if (eq data flag) (setq data newdata)
;; otherwise, combine the previous data with the new
;; data
(setq data (funcall (dictree--meta-dict-combfun dict)
@@ -1491,19 +1512,9 @@ also `dictree-member-p' for testing existence alone.)"
;; if lookup found something, and we're above the lookup
;; cache-threshold, cache the result
(when (and (not (eq data flag))
- (dictree-lookup-cache-threshold dict)
- (or (eq (dictree-lookup-cache-threshold dict) t)
- (and (or (eq (dictree-cache-policy dict) 'time)
- (eq (dictree-cache-policy dict) 'both))
- (>= time
- (dictree-lookup-cache-threshold dict)))
- (and (or (eq (dictree-cache-policy dict) 'length)
- (eq (dictree-cache-policy dict) 'both))
- ;; note: we cache lookups of *longer* keys,
- ;; because those are likely to be slower
- ;; ones
- (>= (length key)
- (dictree-lookup-cache-threshold dict)))))
+ (dictree--above-cache-threshold-p
+ time (length key) (dictree-cache-policy dict)
+ (dictree-lookup-cache-threshold dict) 'long-keys))
(setf (dictree-modified dict) t)
(puthash key data (dictree-lookup-cache dict))))
@@ -2143,18 +2154,9 @@ Returns nil if the stack is empty."
;; if we're above the dictionary's completion cache threshold,
;; cache the result
(when (and (not no-cache)
- cacheparam
- (or (eq cacheparam t)
- (and (or (eq (dictree-cache-policy dic) 'time)
- (eq (dictree-cache-policy dic) 'both))
- (>= time cacheparam))
- (and (or (eq (dictree-cache-policy dic)
- 'length)
- (eq (dictree-cache-policy dic) 'both))
- ;; note: we cache completions of *shorter*
- ;; keys, because those are likely to
- ;; be slower
- (<= (length arg) cacheparam))))
+ (dictree--above-cache-threshold-p
+ time (length arg) (dictree-cache-policy dic)
+ cacheparam))
(setf (dictree-modified dic) t)
(puthash (cons arg reverse)
(dictree--cache-create cmpl maxnum)
- [elpa] externals/dict-tree 0774b51 048/154: Added support for wildcard searches, (continued)
- [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
- [elpa] externals/dict-tree aa22866 062/154: minor fix: added tNFA to required packages, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c53e4b8 064/154: Bumped copyright year, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 61f0ce6 068/154: Bug-fix in dictree--query, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 168cdb5 072/154: Improved edebug-prin1 advice, Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8810d3e 076/154: Bug-fixes to edebug pretty-print functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c1eeabe 081/154: Made dictionary auto-saving more robust against dictionary save failures., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 2666377 084/154: Fixed implementation of 'both cache policy.,
Stefan Monnier <=
- [elpa] externals/dict-tree 5cc5449 091/154: Fixed obsolete functions and other compiler warnings., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 0ea66e7 090/154: Added fboundp guard around ad-define-subr-args (removed in Emacs-24)., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree cfdc73d 099/154: Fixed calls to dictree-create-meta-dict., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 2a1d749 098/154: Minor change to package description, to match other data structure packages., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 7ab8f94 095/154: Updated copyright attribution and license (GPL2 -> GPL3)., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 09b388f 108/154: Add note to self to use cust-print pretty-printing instead of advice., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d96b1c5 097/154: More minor whitespace and commentary changes., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1ec9d58 102/154: Restore trie print/read transformer functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 48ab389 092/154: Simplified persistent-storage code for tries and dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 454c68b 109/154: Code cleanup., Stefan Monnier, 2020/12/14