emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/pyim fbac09e798: Add pyim-numbers>


From: ELPA Syncer
Subject: [elpa] externals/pyim fbac09e798: Add pyim-numbers>
Date: Sun, 9 Jan 2022 10:57:34 -0500 (EST)

branch: externals/pyim
commit fbac09e798c2843febba7aebda726208b4fe2a0b
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Add pyim-numbers>
    
            * tests/pyim-tests.el (pyim-test-pyim-numbers>): New test.
    
            * pyim-dhashcache.el (pyim-dhashcache-sort-words): Use 
pyim-numbers>.
    
            * pyim-common.el (pyim-numbers>): New function.
---
 pyim-common.el      |  8 ++++++++
 pyim-dhashcache.el  | 24 +++++++++---------------
 tests/pyim-tests.el | 12 ++++++++++++
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/pyim-common.el b/pyim-common.el
index 64a5777d0a..2a30a38ea6 100644
--- a/pyim-common.el
+++ b/pyim-common.el
@@ -175,6 +175,14 @@ When CARE-FIRST-ONE is no-nil, ((a b c) (d e)) => (a d)."
        (/ n sum))
      nums)))
 
+(defun pyim-numbers> (a b)
+  "比较数字列表 A 和 B."
+  (if (and (car a) (car b)
+           (equal (car a) (car b)))
+      (pyim-numbers> (cdr a) (cdr b))
+    (> (or (car a) 0)
+       (or (car b) 0))))
+
 (defun pyim-add-unread-command-events (key &optional reset)
   "This function is a fork of `quail-add-unread-command-events'."
   (when reset
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 619cea908b..5d62433b87 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -84,22 +84,16 @@
         (iword2priority pyim-dhashcache-iword2priority))
     (sort words-list
           (lambda (a b)
-            ;; NOTE: 如果以后在 `pyim-dhashcache-count-types' 中添加了新的 count
-            ;; 类型,就需要更新这个地方,使用 ignore-errors 的原因是为了向后兼容,
-            ;; 以后可以删除。
-            (let ((n1 (or (car (ignore-errors (gethash a iword2priority))) 0))
-                  (n2 (or (car (ignore-errors (gethash b iword2priority))) 0)))
+            (let ((p1 (gethash a iword2priority))
+                  (p2 (gethash b iword2priority)))
               (cond
-               ;; NOTE: n1 和 n2 大于某个数字的时候, 用 n1 和 n2 排序可能才靠谱,
-               ;; 但这个数字到底多大合适,暂时不知道,先随意选择一个数字5吧,以后
-               ;; 也许有更好的选择。
-               ((and (> n1 5)
-                     (> n2 5)
-                     (not (= n1 n2)))
-                (> n1 n2))
-               (t (let ((n3 (or (gethash a iword2count) 0))
-                        (n4 (or (gethash b iword2count) 0)))
-                    (> n3 n4)))))))))
+               ((and (listp p1)
+                     (listp p2)
+                     (not (equal p1 p2)))
+                (pyim-numbers> p1 p2))
+               (t (let ((n1 (or (gethash a iword2count) 0))
+                        (n2 (or (gethash b iword2count) 0)))
+                    (> n1 n2)))))))))
 
 (defun pyim-dhashcache-get-counts-from-log (log-info &optional time)
   "从 LOG-INFO 中获取所有的 count 值。
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 8e0c37bbb5..795703e18e 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -162,6 +162,18 @@
   (should (equal (pyim-proportion '(1 2 3 4))
                  '(0.1 0.2 0.3 0.4))))
 
+(ert-deftest pyim-test-pyim-numbers> ()
+  (should-not (pyim-numbers> '(1) '(3)))
+  (should (pyim-numbers> '(4) '(3)))
+  (should-not (pyim-numbers> '(1 2) '(3 4)))
+  (should-not (pyim-numbers> '(1 2) '(1 2)))
+  (should (pyim-numbers> '(2 2) '(1 1)))
+  (should (pyim-numbers> '(2 2) '(1 3)))
+  (should (pyim-numbers> '(2 2) '(1)))
+  (should-not (pyim-numbers> '(2 2) '(3)))
+  (should-not (pyim-numbers> '(2) '(3 1)))
+  (should (pyim-numbers> '(2) '(1 3))))
+
 ;; ** pyim-pymap 相关单元测试
 (ert-deftest pyim-tests-pyim-pymap ()
   (should-not (cl-find-if-not



reply via email to

[Prev in Thread] Current Thread [Next in Thread]