diff options
| author | Paul Eggert | 2013-11-18 10:56:42 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-11-18 10:56:42 -0800 |
| commit | ec2c4ee6d2cb9c5505f120229269941f064b23fa (patch) | |
| tree | 9c0e0ba58f15f602fce7d349cfa89fc665728161 /src | |
| parent | 87d86601022feb7a330fc6344cc85ec65563c1b6 (diff) | |
| download | emacs-ec2c4ee6d2cb9c5505f120229269941f064b23fa.tar.gz emacs-ec2c4ee6d2cb9c5505f120229269941f064b23fa.zip | |
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-consecutive 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.
* src/data.c (Fbool_vector_count_population): Rename from
bool_vector_count_matches, and accept just 1 argument.
(Fbool_vector_count_consecutive): Rename from
Fbool_vector_count_matches_at.
* test/automated/data-tests.el: Adjust to API changes.
Fixes: debbugs:15912
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 14 | ||||
| -rw-r--r-- | src/data.c | 27 |
2 files changed, 26 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 21025c677fc..d6edcea4513 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,19 @@ | |||
| 1 | 2013-11-18 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-11-18 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Improve API of recently-added bool vector functions (Bug#15912). | ||
| 4 | The old API had (bool-vector-count-matches A B) | ||
| 5 | and (bool-vector-count-matches-at A B I), which gave the | ||
| 6 | misleading impression that the two functions were variants, one | ||
| 7 | with a location I. The new API has (bool-vector-count-population A) | ||
| 8 | and (bool-vector-count-consecutive A B I) to make the distinction | ||
| 9 | clearer. The first function no longer has a B argument, since the | ||
| 10 | caller can easily determine the number of nils if the length and | ||
| 11 | number of ts is known. | ||
| 12 | * data.c (Fbool_vector_count_population): Rename from | ||
| 13 | bool_vector_count_matches, and accept just 1 argument. | ||
| 14 | (Fbool_vector_count_consecutive): Rename from | ||
| 15 | Fbool_vector_count_matches_at. | ||
| 16 | |||
| 3 | Always allocate at least one bits_word per bool vector. | 17 | Always allocate at least one bits_word per bool vector. |
| 4 | See Daniel Colascione in: | 18 | See Daniel Colascione in: |
| 5 | http://lists.gnu.org/archive/html/emacs-devel/2013-11/msg00518.html | 19 | http://lists.gnu.org/archive/html/emacs-devel/2013-11/msg00518.html |
diff --git a/src/data.c b/src/data.c index b8b0f248dfa..2c789f37431 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -3282,11 +3282,12 @@ Return the destination vector. */) | |||
| 3282 | return b; | 3282 | return b; |
| 3283 | } | 3283 | } |
| 3284 | 3284 | ||
| 3285 | DEFUN ("bool-vector-count-matches", Fbool_vector_count_matches, | 3285 | DEFUN ("bool-vector-count-population", Fbool_vector_count_population, |
| 3286 | Sbool_vector_count_matches, 2, 2, 0, | 3286 | Sbool_vector_count_population, 1, 1, 0, |
| 3287 | doc: /* Count how many elements in A equal B. | 3287 | doc: /* Count how many elements in A are t. |
| 3288 | A must be a bool vector. B is a generalized bool. */) | 3288 | A is a bool vector. To count A's nil elements, subtract the return |
| 3289 | (Lisp_Object a, Lisp_Object b) | 3289 | value from A's length. */) |
| 3290 | (Lisp_Object a) | ||
| 3290 | { | 3291 | { |
| 3291 | EMACS_INT count; | 3292 | EMACS_INT count; |
| 3292 | EMACS_INT nr_bits; | 3293 | EMACS_INT nr_bits; |
| @@ -3303,17 +3304,13 @@ A must be a bool vector. B is a generalized bool. */) | |||
| 3303 | for (i = 0; i < nwords; i++) | 3304 | for (i = 0; i < nwords; i++) |
| 3304 | count += count_one_bits_word (adata[i]); | 3305 | count += count_one_bits_word (adata[i]); |
| 3305 | 3306 | ||
| 3306 | if (NILP (b)) | ||
| 3307 | count = nr_bits - count; | ||
| 3308 | return make_number (count); | 3307 | return make_number (count); |
| 3309 | } | 3308 | } |
| 3310 | 3309 | ||
| 3311 | DEFUN ("bool-vector-count-matches-at", | 3310 | DEFUN ("bool-vector-count-consecutive", Fbool_vector_count_consecutive, |
| 3312 | Fbool_vector_count_matches_at, | 3311 | Sbool_vector_count_consecutive, 3, 3, 0, |
| 3313 | Sbool_vector_count_matches_at, 3, 3, 0, | 3312 | doc: /* Count how many consecutive elements in A equal B starting at I. |
| 3314 | doc: /* Count how many consecutive elements in A equal B at i. | 3313 | A is a bool vector, B is t or nil, and I is an index into A. */) |
| 3315 | A must be a bool vector. B is a generalized boolean. i is an | ||
| 3316 | index into the vector. */) | ||
| 3317 | (Lisp_Object a, Lisp_Object b, Lisp_Object i) | 3314 | (Lisp_Object a, Lisp_Object b, Lisp_Object i) |
| 3318 | { | 3315 | { |
| 3319 | EMACS_INT count; | 3316 | EMACS_INT count; |
| @@ -3660,8 +3657,8 @@ syms_of_data (void) | |||
| 3660 | defsubr (&Sbool_vector_set_difference); | 3657 | defsubr (&Sbool_vector_set_difference); |
| 3661 | defsubr (&Sbool_vector_not); | 3658 | defsubr (&Sbool_vector_not); |
| 3662 | defsubr (&Sbool_vector_subsetp); | 3659 | defsubr (&Sbool_vector_subsetp); |
| 3663 | defsubr (&Sbool_vector_count_matches); | 3660 | defsubr (&Sbool_vector_count_consecutive); |
| 3664 | defsubr (&Sbool_vector_count_matches_at); | 3661 | defsubr (&Sbool_vector_count_population); |
| 3665 | 3662 | ||
| 3666 | set_symbol_function (Qwholenump, XSYMBOL (Qnatnump)->function); | 3663 | set_symbol_function (Qwholenump, XSYMBOL (Qnatnump)->function); |
| 3667 | 3664 | ||