[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu ed0ba822c9 07/14: Use exponential decay
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu ed0ba822c9 07/14: Use exponential decay |
Date: |
Sun, 6 Apr 2025 09:58:02 -0400 (EDT) |
branch: externals/corfu
commit ed0ba822c90b8c345877bd58fc4189b2773fd328
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Use exponential decay
---
extensions/corfu-history.el | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/extensions/corfu-history.el b/extensions/corfu-history.el
index 1fbf3b4398..c1d505960a 100644
--- a/extensions/corfu-history.el
+++ b/extensions/corfu-history.el
@@ -50,11 +50,18 @@ or the property `history-length' of `corfu-history'.")
"Hash table of Corfu candidates.")
(defcustom corfu-history-duplicate 10
- "Number of history positions gained by duplicate history elements.
+ "Maximal number of history positions gained by duplicate history elements.
The more often a duplicate element occurs in the history, the earlier it
-appears in the completion list. Note that duplicates occur only if
+appears in the completion list. The position gain decays exponentially
+with `corfu-history-decay'. Note that duplicates occur only if
`history-delete-duplicates' is disabled."
- :type 'natum
+ :type 'number
+ :group 'corfu)
+
+(defcustom corfu-history-decay 0.005
+ "Exponential decay for the position gain of duplicate elements.
+See also `corfu-history-duplicate'."
+ :type 'float
:group 'corfu)
(defun corfu-history--sort-predicate (x y)
@@ -67,11 +74,14 @@ appears in the completion list. Note that duplicates occur
only if
"Sort CANDS by history."
(unless corfu-history--hash
(let ((ht (make-hash-table :test #'equal :size (length corfu-history))))
- (cl-loop for elem in corfu-history for idx from 0 do
- (puthash elem (if-let ((n (gethash elem ht)))
- (- n corfu-history-duplicate)
- (if (= idx 0) (/ most-negative-fixnum 2) idx))
- ht))
+ (cl-loop for elem in corfu-history for idx from 0
+ for w = (if-let ((w (gethash elem ht)))
+ ;; Reduce duplicate weight with exponential decay.
+ (- w (round (* corfu-history-duplicate
+ (exp (* -1.0 corfu-history-decay
idx)))))
+ ;; Never outrank the most recent element.
+ (if (= idx 0) (/ most-negative-fixnum 2) idx))
+ do (puthash elem w ht))
(setq corfu-history--hash ht)))
(cl-loop for ht = corfu-history--hash for max = most-positive-fixnum
for cand on cands do
- [elpa] externals/corfu updated (13fb95fa99 -> cd02e15267), ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 3a8a03110b 01/14: Add corfu-history-duplicate, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 4accd4b0a5 04/14: Improve corfu-history--sort, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 54a789c9ed 02/14: history-length can be t, don't use it., ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 7b527613e6 03/14: Improve docstring, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 70dba3ff51 08/14: Update commentary, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 101002411e 09/14: Update changelog, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu cd02e15267 14/14: Update changelog, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 3303743cf1 13/14: Update changelog, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu ed0ba822c9 07/14: Use exponential decay,
ELPA Syncer <=
- [elpa] externals/corfu bb2b8d484c 11/14: README: Update configuration, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu ab3de89622 12/14: Express decay in history shifts, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu dee10bbddb 10/14: Automatically save corfu-history, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 69930d3ac7 06/14: Improve docstring, ELPA Syncer, 2025/04/06
- [elpa] externals/corfu 0125888430 05/14: Use constant step size, make sure that most recent is never outranked, ELPA Syncer, 2025/04/06