[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/flx c45daa261c 124/182: refactor: pull out flx-get-matches
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/flx c45daa261c 124/182: refactor: pull out flx-get-matches-worker function |
Date: |
Tue, 13 Dec 2022 03:59:36 -0500 (EST) |
branch: elpa/flx
commit c45daa261c3fca5abc06a5ede250615a57971990
Author: Le Wang <l26wang@gmail.com>
Commit: Le Wang <l26wang@gmail.com>
refactor: pull out flx-get-matches-worker function
---
flx.el | 112 ++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 52 insertions(+), 60 deletions(-)
diff --git a/flx.el b/flx.el
index 0d37dbb9cd..17c4fe560b 100644
--- a/flx.el
+++ b/flx.el
@@ -245,76 +245,68 @@ See documentation for logic."
(puthash str res cache))
res))))
+(defun flx-get-matches-worker (greater-than q-index query-length heatmap
match-cache str-info query)
+ (let ((hash-key (+ q-index
+ (* (or greater-than 0)
+ query-length))))
+ (or
+ (gethash hash-key match-cache)
+ (puthash
+ hash-key
+ (let ((indexes (flx-bigger-sublist
+ (gethash (aref query q-index) str-info)
+ greater-than)))
+ (if (>= q-index (1- query-length))
+ (mapcar (lambda (index)
+ (cons (list index)
+ (cons (aref heatmap index) 0))) indexes)
+ (let ((match) (best-score most-negative-fixnum))
+ (dolist (index indexes (and match (list match)))
+ (dolist (elem (flx-get-matches-worker index (1+ q-index)
+ query-length heatmap
match-cache str-info query))
+ (setq elem
+ (cons (cons index (car elem))
+ (cons
+ (+ (cadr elem)
+ (aref heatmap index)
+ (if (= (1- (caar elem)) index)
+ (+ (* (min (cddr elem)
+ 3)
+ 15)
+ 60)
+ 0))
+ (if (= (1- (caar elem)) index)
+ (1+ (cddr elem))
+ 0))))
+ ;; we only care about the optimal score
+ (when (> (cadr elem) best-score)
+ (setq best-score (cadr elem)
+ match elem)))))))
+ match-cache))))
(defun flx-score (str query &optional cache)
"return best score matching QUERY against STR"
(unless (or (zerop (length query))
(zerop (length str)))
- (cl-letf*
- ((hash (flx-process-cache str cache))
- (heatmap (gethash 'heatmap hash))
+ (let*
+ ((str-info (flx-process-cache str cache))
+ (heatmap (gethash 'heatmap str-info))
(query-length (length query))
- (full-match-boost (and (< query-length 5)
- (> query-length 1)))
+ (full-match-boost (< 1 query-length 5))
;; Dynamic Programming table
(match-cache (make-hash-table :test 'eql :size 10))
-
- ;; local variable to be used later
- (indexes nil)
- (hash-key 0)
-
- ((symbol-function #'flx-get-matches-worker)
- (lambda (greater-than q-index)
- (or
- (gethash
- (setq hash-key (+ q-index
- (* (or greater-than 0)
- query-length)))
- match-cache)
- (puthash
- hash-key
- (progn
- (setq indexes (flx-bigger-sublist
- (gethash (aref query q-index) hash)
- greater-than))
- (if (>= q-index (1- query-length))
- (mapcar (lambda (index)
- (cons (list index)
- (cons (aref heatmap index) 0))) indexes)
- (let ((match) (best-score most-negative-fixnum))
- (dolist (index indexes (and match (list match)))
- (dolist (elem (flx-get-matches-worker index (1+
q-index)))
- (setq elem
- (cons (cons index (car elem))
- (cons
- (+ (cadr elem)
- (aref heatmap index)
- (if (= (1- (caar elem)) index)
- (+ (* (min (cddr elem)
- 3)
- 15)
- 60)
- 0))
- (if (= (1- (caar elem)) index)
- (1+ (cddr elem))
- 0))))
- ;; we only care about the optimal score
- (when (> (cadr elem) best-score)
- (setq best-score (cadr elem)
- match elem)))))))
- match-cache)))))
-
+ (res (flx-get-matches-worker nil 0
+ query-length heatmap match-cache
str-info query)))
;; postprocess candidate
- (let ((res (flx-get-matches-worker nil 0)))
- (and res
- (cons (+ (cadar res)
- (if (and full-match-boost
- (= (length (caar res))
- (length str)))
- 10000
- 0))
- (caar res)))))))
+ (and res
+ (cons (+ (cadar res)
+ (if (and full-match-boost
+ (= (length (caar res))
+ (length str)))
+ 10000
+ 0))
+ (caar res))))))
(defun flx-propertize (obj score &optional add-score)
"Return propertized copy of obj according to score.
- [nongnu] elpa/flx 114cf369cb 020/182: add ido installation instructions, (continued)
- [nongnu] elpa/flx 114cf369cb 020/182: add ido installation instructions, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 7452ab1c79 021/182: README update, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx f566207c82 015/182: travis config update, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 01eef11b96 033/182: small efficiency fix, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 44951ac311 042/182: simplify caching, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx cc3258bb10 038/182: cache key should be based on whole input, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 771f61f3fd 016/182: update test list, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx a792c2c5f1 053/182: change advice to before, fix comments, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 61dcc4f563 089/182: Reset caches on file reload., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 24f5d2cfc5 099/182: Fix typo threshhold -> threshold, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx c45daa261c 124/182: refactor: pull out flx-get-matches-worker function,
ELPA Syncer <=
- [nongnu] elpa/flx b9399afd48 136/182: Simplify math operations in score calculation, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 8419b1b28f 107/182: Bump version to v0.4 ., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 46dd7d7edb 144/182: Improve readability, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 807d694555 154/182: remove reference to `flx-ido-big-demo`, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx e05105872f 169/182: Begin sentences with capital letters and end them with a periods, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx dd47185f5b 173/182: flx-inc-vec: Improve doc-string, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 2a816e25df 151/182: Add file misc/.nosearch, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 4cf3f5ad45 059/182: Merge pull request #25 from bbatsov/improve-headers, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 11422574e5 166/182: Merge pull request #106 from jcs-PR/badge, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 647cb2f92f 168/182: Merge pull request #104 from phst/nocl, ELPA Syncer, 2022/12/13