This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
pravin gerrit-no-reply at lists.osmocom.orgHello Jenkins Builder, Holger Freyther, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/415 to look at the new patch set (#3). Add function to get uninterrupted bit run Function bitvec_rl_curbit added to get number of uninterrupted bits run in vector starting from the current bit till max number of bits. Change-Id: Iae153d3639ea6b891c1fc10d7801a435c9492e26 --- M include/osmocom/core/bitvec.h M src/bitvec.c 2 files changed, 55 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/15/415/3 diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h index 19e2af8..0e17ba7 100644 --- a/include/osmocom/core/bitvec.h +++ b/include/osmocom/core/bitvec.h @@ -89,6 +89,7 @@ void bitvec_to_string_r(const struct bitvec *bv, char *str); void bitvec_zero(struct bitvec *bv); unsigned bitvec_rl(const struct bitvec *bv, bool b); +unsigned bitvec_rl_curbit(struct bitvec *bv, bool b, int max_bits); void bitvec_shiftl(struct bitvec *bv, unsigned int n); int16_t bitvec_get_int16_msb(const struct bitvec *bv, unsigned int num_bits); unsigned int bitvec_add_array(struct bitvec *bv, const uint32_t *array, diff --git a/src/bitvec.c b/src/bitvec.c index 38148ac..718beda 100644 --- a/src/bitvec.c +++ b/src/bitvec.c @@ -575,6 +575,60 @@ return bv->cur_bit; } +/* \brief Return number (bits) of uninterrupted bit run in vector + * starting from the current bit + * \param[in] bv The boolean vector to work on + * \param[in] b The boolean, sequence of 1's or 0's to be checked + * \returns Number of consecutive bits of \p b in \p bv + */ +unsigned bitvec_rl_curbit(struct bitvec *bv, bool b, int max_bits) +{ + unsigned i = 0; + int temp_res = 0; + int count = 0; + unsigned readIndex = bv->cur_bit; + if (bv->cur_bit % 8 == 0) { + for (i = (bv->cur_bit/8); + i < (max_bits % 8 ? max_bits/8 + 1 : max_bits/8); + i++, count++) { + if ((b ? 0xFF : 0) != bv->data[i]) { + bv->cur_bit = (count * 8 + + leading_bits(bv->data[i], b) + readIndex); + return count * 8 + leading_bits(bv->data[i], b); + } + } + bv->cur_bit = (count * 8) + readIndex; + if (bv->cur_bit > max_bits) + bv->cur_bit = max_bits; + return (bv->cur_bit - readIndex); + } + int pos = bv->cur_bit/8; + + while (readIndex < max_bits && bitvec_read_field(bv, &readIndex, 1) == b) { + if (bv->cur_bit % 8 >= 0) + temp_res++; + else { + pos++; + for (i = pos; + i < (max_bits % 8 ? max_bits/8 + 1 : max_bits/8); + i++, count++) { + if ((b ? 0xFF : 0) != bv->data[i]) { + bv->cur_bit = (count * 8 + + leading_bits(bv->data[i], b) + + temp_res) + readIndex; + return count * 8 + + leading_bits(bv->data[i], b) + + temp_res; + } + } + bv->cur_bit = (temp_res + (count * 8)) + readIndex; + return temp_res + (count * 8); + } + } + bv->cur_bit--; + return temp_res; +} + /*! \brief Shifts bitvec to the left, n MSB bits lost */ void bitvec_shiftl(struct bitvec *bv, unsigned n) { -- To view, visit https://gerrit.osmocom.org/415 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: Iae153d3639ea6b891c1fc10d7801a435c9492e26 Gerrit-PatchSet: 3 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: prasadkg <Prasad.Kaup at radisys.com> Gerrit-Reviewer: Holger Freyther <holger at freyther.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Max <msuraev at sysmocom.de> Gerrit-Reviewer: prasadkg <Prasad.Kaup at radisys.com>