diff --git a/include/sdsl/select_support_mcl.hpp b/include/sdsl/select_support_mcl.hpp index 3cd826c12..dab03232b 100644 --- a/include/sdsl/select_support_mcl.hpp +++ b/include/sdsl/select_support_mcl.hpp @@ -102,6 +102,8 @@ class select_support_mcl : public select_support select_support_mcl& operator=(const select_support_mcl& ss); select_support_mcl& operator=(select_support_mcl&&); void swap(select_support_mcl& ss); + //! Estimate for the number of bits used by this data structure. + size_t bits_used(); }; @@ -170,6 +172,23 @@ void select_support_mcl::swap(select_support_mcl& ss) std::swap(m_arg_cnt, ss.m_arg_cnt); } +template +size_t select_support_mcl::bits_used() +{ + size_t bits = sizeof(*this)*8; + // number of superblocks in the data structure + size_type sb = (m_arg_cnt+4095)>>12; + if (m_arg_cnt) { // if there exists 1-bits to be supported + bits += m_superblock.capacity() + sizeof(m_superblock)*8; + bits += sb*sizeof(m_longsuperblock[0])*8 + sb*sizeof(m_miniblock[0])*8; + for (size_type i=0; i < sb; ++i) { + bits += (m_longsuperblock == nullptr) ? 0 : m_longsuperblock[i].capacity(); + bits += (m_miniblock == nullptr) ? 0 : m_miniblock[i].capacity(); + } + } + return bits; +} + template void select_support_mcl::copy(const select_support_mcl& ss) {