From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#15912: Improve API of recently-added bool vector functions. Date: Sun, 17 Nov 2013 00:39:06 -0800 Organization: UCLA Computer Science Department Message-ID: <528880AA.2020401@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090306070904030905000903" X-Trace: ger.gmane.org 1384677617 9651 80.91.229.3 (17 Nov 2013 08:40:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 17 Nov 2013 08:40:17 +0000 (UTC) To: 15912@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 17 09:40:21 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vhxtx-0008Eu-TR for geb-bug-gnu-emacs@m.gmane.org; Sun, 17 Nov 2013 09:40:18 +0100 Original-Received: from localhost ([::1]:38363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vhxtx-0001IZ-B3 for geb-bug-gnu-emacs@m.gmane.org; Sun, 17 Nov 2013 03:40:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vhxtp-0001IT-Ry for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:40:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vhxtk-0003Uc-O0 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:40:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:43978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vhxtk-0003UM-Jr for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:40:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Vhxtj-0003nW-Ck for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:40:04 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 17 Nov 2013 08:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 15912 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.138467758014562 (code B ref -1); Sun, 17 Nov 2013 08:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Nov 2013 08:39:40 +0000 Original-Received: from localhost ([127.0.0.1]:57997 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VhxtL-0003mm-9p for submit@debbugs.gnu.org; Sun, 17 Nov 2013 03:39:40 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56110) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VhxtH-0003mX-9L for submit@debbugs.gnu.org; Sun, 17 Nov 2013 03:39:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vhxt6-0003CG-Rr for submit@debbugs.gnu.org; Sun, 17 Nov 2013 03:39:29 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:51988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vhxt6-0003CC-OI for submit@debbugs.gnu.org; Sun, 17 Nov 2013 03:39:24 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vhxt1-0001Bo-UI for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:39:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vhxsx-000393-6v for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:39:19 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:42032) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vhxsw-0002zx-R8 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2013 03:39:15 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 14197A60001; Sun, 17 Nov 2013 00:39:08 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uZKz9SQnZrg3; Sun, 17 Nov 2013 00:39:07 -0800 (PST) Original-Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id E06F139E8008; Sun, 17 Nov 2013 00:39:06 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 X-Enigmail-Version: 1.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:80679 Archived-At: This is a multi-part message in MIME format. --------------090306070904030905000903 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Tags: patch Here's a proposed patch to improve the API of the recently-added bool vector functions. I'm CC'ing this to Daniel Colascione to give him a heads-up, since he added the functions. I figure we should get this resolved soon, before the functions are frozen for 24.4. --------------090306070904030905000903 Content-Type: text/x-patch; name="boolvec.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="boolvec.diff" === modified file 'etc/NEWS' --- etc/NEWS 2013-11-11 05:18:53 +0000 +++ etc/NEWS 2013-11-17 08:33:44 +0000 @@ -728,8 +728,8 @@ *** `bool-vector-set-difference' *** `bool-vector-not' *** `bool-vector-subsetp' -*** `bool-vector-count-matches' -*** `bool-vector-count-matches-at' +*** `bool-vector-count-leading' +*** `bool-vector-count-population' ** Comparison functions =, <, >, <=, >= now take many arguments. === modified file 'src/ChangeLog' --- src/ChangeLog 2013-11-17 03:58:30 +0000 +++ src/ChangeLog 2013-11-17 08:33:44 +0000 @@ -1,5 +1,19 @@ 2013-11-17 Paul Eggert + Improve API of recently-added bool vector functions. + The old API had (bool-vector-count-matches A B) + and (bool-vector-count-matches-at A B I), which gave the + misleading impression that the two functions were variants, one + with a location I. The new API has (bool-vector-count-population A) + and (bool-vector-count-leading A B I) to make the distinction + clearer. The first function no longer has a B argument, since the + caller can easily determine the number of nils if the length and + number of ts is known. + * data.c (Fbool_vector_count_population): Rename from + bool_vector_count_matches, and accept just 1 argument. + (Fbool_vector_count_leading): Rename from + Fbool_vector_count_matches_at. + * lisp.h (DEBUGGER_SEES_C_MACROS): Remove. 2013-11-16 Eli Zaretskii === modified file 'src/data.c' --- src/data.c 2013-11-15 18:01:04 +0000 +++ src/data.c 2013-11-17 08:33:44 +0000 @@ -3247,11 +3247,12 @@ return b; } -DEFUN ("bool-vector-count-matches", Fbool_vector_count_matches, - Sbool_vector_count_matches, 2, 2, 0, - doc: /* Count how many elements in A equal B. -A must be a bool vector. B is a generalized bool. */) - (Lisp_Object a, Lisp_Object b) +DEFUN ("bool-vector-count-population", Fbool_vector_count_population, + Sbool_vector_count_population, 1, 1, 0, + doc: /* Count how many elements in A are t. +A is a bool vector. To count A's nil elements, subtract the return +value from A's length. */) + (Lisp_Object a) { EMACS_INT count; EMACS_INT nr_bits; @@ -3268,17 +3269,13 @@ for (i = 0; i < nwords; i++) count += count_one_bits_word (adata[i]); - if (NILP (b)) - count = nr_bits - count; return make_number (count); } -DEFUN ("bool-vector-count-matches-at", - Fbool_vector_count_matches_at, - Sbool_vector_count_matches_at, 3, 3, 0, - doc: /* Count how many consecutive elements in A equal B at i. -A must be a bool vector. B is a generalized boolean. i is an -index into the vector. */) +DEFUN ("bool-vector-count-leading", Fbool_vector_count_leading, + Sbool_vector_count_leading, 3, 3, 0, + doc: /* Count how many consecutive elements in A equal B starting at I. +A is a bool vector, B is t or nil, and I is an index into A. */) (Lisp_Object a, Lisp_Object b, Lisp_Object i) { EMACS_INT count; @@ -3622,8 +3619,8 @@ defsubr (&Sbool_vector_set_difference); defsubr (&Sbool_vector_not); defsubr (&Sbool_vector_subsetp); - defsubr (&Sbool_vector_count_matches); - defsubr (&Sbool_vector_count_matches_at); + defsubr (&Sbool_vector_count_leading); + defsubr (&Sbool_vector_count_population); set_symbol_function (Qwholenump, XSYMBOL (Qnatnump)->function); === modified file 'test/ChangeLog' --- test/ChangeLog 2013-11-16 11:46:37 +0000 +++ test/ChangeLog 2013-11-17 08:33:44 +0000 @@ -1,3 +1,8 @@ +2013-11-17 Paul Eggert + + Improve API of recently-added bool vector functions. + * automated/data-tests.el: Adjust to API changes. + 2013-11-16 Michael Albinus * automated/tramp-tests.el (tramp-test07-file-exists-p) === modified file 'test/automated/data-tests.el' --- test/automated/data-tests.el 2013-09-22 09:31:55 +0000 +++ test/automated/data-tests.el 2013-11-17 08:33:44 +0000 @@ -77,42 +77,40 @@ ;; Bool vector tests. Compactly represent bool vectors as hex ;; strings. -(ert-deftest bool-vector-count-matches-all-0-nil () +(ert-deftest bool-vector-count-population-all-0-nil () (cl-loop for sz in '(0 45 1 64 9 344) do (let* ((bv (make-bool-vector sz nil))) (should + (zerop + (bool-vector-count-population bv)))))) + +(ert-deftest bool-vector-count-population-all-1-t () + (cl-loop for sz in '(0 45 1 64 9 344) + do (let* ((bv (make-bool-vector sz t))) + (should (eql - (bool-vector-count-matches bv nil) + (bool-vector-count-population bv) sz))))) -(ert-deftest bool-vector-count-matches-all-0-t () - (cl-loop for sz in '(0 45 1 64 9 344) - do (let* ((bv (make-bool-vector sz nil))) - (should - (eql - (bool-vector-count-matches bv t) - 0))))) - -(ert-deftest bool-vector-count-matches-1-nil () - (let* ((bv (make-bool-vector 45 nil))) - (aset bv 40 t) - (aset bv 0 t) - (should - (eql - (bool-vector-count-matches bv t) - 2))) - ) - -(ert-deftest bool-vector-count-matches-1-t () - (let* ((bv (make-bool-vector 45 nil))) - (aset bv 40 t) - (aset bv 0 t) - (should - (eql - (bool-vector-count-matches bv nil) +(ert-deftest bool-vector-count-population-1-nil () + (let* ((bv (make-bool-vector 45 nil))) + (aset bv 40 t) + (aset bv 0 t) + (should + (eql + (bool-vector-count-population bv) + 2)))) + +(ert-deftest bool-vector-count-population-1-t () + (let* ((bv (make-bool-vector 45 t))) + (aset bv 40 nil) + (aset bv 0 nil) + (should + (eql + (bool-vector-count-population bv) 43)))) -(defun mock-bool-vector-count-matches-at (a b i) +(defun mock-bool-vector-count-leading (a b i) (loop for i from i below (length a) while (eq (aref a i) b) sum 1)) @@ -147,8 +145,8 @@ (nreverse nibbles) ""))) -(defun test-bool-vector-count-matches-at-tc (desc) - "Run a test case for bool-vector-count-matches-at. +(defun test-bool-vector-count-leading-tc (desc) + "Run a test case for bool-vector-count-leading. DESC is a string describing the test. It is a sequence of hexadecimal digits describing the bool vector. We exhaustively test all counts at all possible positions in the vector by @@ -158,8 +156,8 @@ for lf in '(nil t) do (loop for pos from 0 upto (length bv) - for cnt = (mock-bool-vector-count-matches-at bv lf pos) - for rcnt = (bool-vector-count-matches-at bv lf pos) + for cnt = (mock-bool-vector-count-leading bv lf pos) + for rcnt = (bool-vector-count-leading bv lf pos) unless (eql cnt rcnt) do (error "FAILED testcase %S %3S %3S %3S" pos lf cnt rcnt))))) @@ -182,8 +180,8 @@ "0000000000000000000000000" "FFFFFFFFFFFFFFFF1")) -(ert-deftest bool-vector-count-matches-at () - (mapc #'test-bool-vector-count-matches-at-tc +(ert-deftest bool-vector-count-leading () + (mapc #'test-bool-vector-count-leading-tc bool-vector-test-vectors)) (defun test-bool-vector-apply-mock-op (mock a b c) --------------090306070904030905000903--