forked from premiere/premiere-libtorrent
move bitfield's find_first_set and find_last_clear into cpp file (#1155)
This commit is contained in:
parent
97c6a75084
commit
179e238561
|
@ -154,25 +154,8 @@ namespace libtorrent
|
||||||
|
|
||||||
// count the number of bits in the bitfield that are set to 1.
|
// count the number of bits in the bitfield that are set to 1.
|
||||||
int count() const;
|
int count() const;
|
||||||
int find_first_set() const
|
int find_first_set() const;
|
||||||
{
|
int find_last_clear() const;
|
||||||
size_t const num = num_words();
|
|
||||||
if (num == 0) return -1;
|
|
||||||
int const count = aux::count_leading_zeros({&m_buf[1], num});
|
|
||||||
return count != int(num) * 32 ? count : -1;
|
|
||||||
}
|
|
||||||
int find_last_clear() const
|
|
||||||
{
|
|
||||||
size_t const num = num_words();
|
|
||||||
if (num == 0) return - 1;
|
|
||||||
int const size = this->size();
|
|
||||||
std::uint32_t const mask = 0xffffffff << (32 - (size & 31));
|
|
||||||
std::uint32_t const last = m_buf[num] ^ aux::host_to_network(mask);
|
|
||||||
int const ext = aux::count_trailing_ones(~last) - (31 - (size % 32));
|
|
||||||
return last != 0
|
|
||||||
? (int(num) - 1) * 32 + ext
|
|
||||||
: size - (aux::count_trailing_ones({&m_buf[1], num - 1}) + ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct const_iterator
|
struct const_iterator
|
||||||
{
|
{
|
||||||
|
|
|
@ -190,4 +190,25 @@ namespace libtorrent
|
||||||
clear_trailing_bits();
|
clear_trailing_bits();
|
||||||
TORRENT_ASSERT(size() == bits);
|
TORRENT_ASSERT(size() == bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bitfield::find_first_set() const
|
||||||
|
{
|
||||||
|
size_t const num = num_words();
|
||||||
|
if (num == 0) return -1;
|
||||||
|
int const count = aux::count_leading_zeros({&m_buf[1], num});
|
||||||
|
return count != int(num) * 32 ? count : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bitfield::find_last_clear() const
|
||||||
|
{
|
||||||
|
size_t const num = num_words();
|
||||||
|
if (num == 0) return - 1;
|
||||||
|
int const size = this->size();
|
||||||
|
std::uint32_t const mask = 0xffffffff << (32 - (size & 31));
|
||||||
|
std::uint32_t const last = m_buf[num] ^ aux::host_to_network(mask);
|
||||||
|
int const ext = aux::count_trailing_ones(~last) - (31 - (size % 32));
|
||||||
|
return last != 0
|
||||||
|
? (int(num) - 1) * 32 + ext
|
||||||
|
: size - (aux::count_trailing_ones({&m_buf[1], num - 1}) + ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue