Skip to content

Commit

Permalink
add link to changelog - more consistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanschnell committed Feb 19, 2023
1 parent 6e52e49 commit 2db5357
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGE_LOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* retire `bitcount_lookup[256]` table
* improve `util.count_n()` error messages
* avoid `util` module tests from being run more than once in each
call to `bitarray.test()` when called multiple times
call to `bitarray.test()` when called multiple times in the same
Python process, see #6e52e49a
* improve testing


Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ This sub-module was added in version 1.2.

``count_n(a, n, value=1, /)`` -> int
Return lowest index ``i`` for which ``a[:i].count(value) == n``.
Raises ``ValueError``, when n exceeds total count (``a.count(value)``).
Raises ``ValueError`` when ``n`` exceeds total count (``a.count(value)``).

New in version 2.3.6: optional value argument.

Expand Down
16 changes: 8 additions & 8 deletions bitarray/_bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ setrange(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b, int vi)
assert(self->readonly == 0);

if (b >= a + 8) {
const Py_ssize_t byte_a = BYTES(a);
const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */
const Py_ssize_t byte_b = b / 8;

assert(a + 8 > 8 * byte_a && 8 * byte_b + 8 > b);
Expand Down Expand Up @@ -455,7 +455,7 @@ count(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b)
cnt += count(self, 64 * wb, b);
}
else if (n >= 8) {
const Py_ssize_t byte_a = BYTES(a);
const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */
const Py_ssize_t byte_b = b / 8;

assert(8 * byte_a - a < 8 && b - 8 * byte_b < 8);
Expand Down Expand Up @@ -494,25 +494,25 @@ find_bit(bitarrayobject *self, int vi, Py_ssize_t a, Py_ssize_t b)
Note that we cannot check for n >= 64 here as the function could then
go into an infinite recursive loop when a word is found. */
if (n > 64) {
const Py_ssize_t word_a = (a + 63) / 64;
const Py_ssize_t word_b = b / 64;
const Py_ssize_t wa = (a + 63) / 64; /* word range(wa, wb) */
const Py_ssize_t wb = b / 64;
const uint64_t *wbuff = WBUFF(self);
const uint64_t w = vi ? 0 : ~0;

if ((res = find_bit(self, vi, a, 64 * word_a)) >= 0)
if ((res = find_bit(self, vi, a, 64 * wa)) >= 0)
return res;

for (i = word_a; i < word_b; i++) { /* skip uint64 words */
for (i = wa; i < wb; i++) { /* skip uint64 words */
assert_byte_in_range(self, 8 * i + 7);
if (w ^ wbuff[i])
return find_bit(self, vi, 64 * i, 64 * i + 64);
}
return find_bit(self, vi, 64 * word_b, b);
return find_bit(self, vi, 64 * wb, b);
}

/* For the same reason as above, we cannot check for n >= 8 here. */
if (n > 8) {
const Py_ssize_t byte_a = BYTES(a);
const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */
const Py_ssize_t byte_b = b / 8;
const char *buff = self->ob_item;
const char c = vi ? 0 : ~0;
Expand Down
12 changes: 6 additions & 6 deletions bitarray/_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,23 @@ find_last(bitarrayobject *self, int vi, Py_ssize_t a, Py_ssize_t b)

/* the logic here is the same as in find_bit() in _bitarray.c */
if (n > 64) {
const Py_ssize_t word_a = (a + 63) / 64;
const Py_ssize_t word_b = b / 64;
const Py_ssize_t wa = (a + 63) / 64; /* word range(wa, wb) */
const Py_ssize_t wb = b / 64;
const uint64_t *wbuff = WBUFF(self);
const uint64_t w = vi ? 0 : ~0;

if ((res = find_last(self, vi, 64 * word_b, b)) >= 0)
if ((res = find_last(self, vi, 64 * wb, b)) >= 0)
return res;

for (i = word_b - 1; i >= word_a; i--) { /* skip uint64 words */
for (i = wb - 1; i >= wa; i--) { /* skip uint64 words */
if (w ^ wbuff[i])
return find_last(self, vi, 64 * i, 64 * i + 64);
}
return find_last(self, vi, a, 64 * word_a);
return find_last(self, vi, a, 64 * wa);
}

if (n > 8) {
const Py_ssize_t byte_a = BYTES(a);
const Py_ssize_t byte_a = BYTES(a); /* byte range(byte_a, byte_b) */
const Py_ssize_t byte_b = b / 8;
const char *buff = self->ob_item;
const char c = vi ? 0 : ~0;
Expand Down

0 comments on commit 2db5357

Please sign in to comment.