/*! \param i Argument for the length of the prefix v[0..i-1], with \f$0\leq i \leq size()\f$. \returns Number of 1-bits in the prefix [0..i-1] of the original bit_vector. \par Time complexity \f$ \Order{ sample\_rate of the rrr\_vector} \f$ */ const size_type rank(size_type i)const { assert(m_v != nullptr); assert(i <= m_v->size()); size_type bt_idx = i/t_bs; size_type sample_pos = bt_idx/t_k; size_type btnrp = m_v->m_btnrp[ sample_pos ]; size_type rank = m_v->m_rank[ sample_pos ]; if (sample_pos+1 < m_v->m_rank.size()) { size_type diff_rank = m_v->m_rank[ sample_pos+1 ] - rank; #ifndef RRR_NO_OPT if (diff_rank == (size_type)0) { return rank_support_rrr_trait<t_b>::adjust_rank(rank, i); } else if (diff_rank == (size_type)t_bs*t_k) { return rank_support_rrr_trait<t_b>::adjust_rank( rank + i - sample_pos*t_k*t_bs, i); } #endif } const bool inv = m_v->m_invert[ sample_pos ]; for (size_type j = sample_pos*t_k; j < bt_idx; ++j) { uint16_t r = m_v->m_bt[j]; rank += (inv ? t_bs - r: r); btnrp += rrr_helper_type::space_for_bt(r); } uint16_t off = i % t_bs; if (!off) { // needed for special case: if i=size() is a multiple of t_bs // the access to m_bt would cause a invalid memory access return rank_support_rrr_trait<t_b>::adjust_rank(rank, i); } uint16_t bt = inv ? t_bs - m_v->m_bt[ bt_idx ] : m_v->m_bt[ bt_idx ]; uint16_t btnrlen = rrr_helper_type::space_for_bt(bt); number_type btnr = rrr_helper_type::decode_btnr(m_v->m_btnr, btnrp, btnrlen); uint16_t popcnt = rrr_helper_type::decode_popcount(bt, btnr, off); return rank_support_rrr_trait<t_b>::adjust_rank(rank + popcnt, i); }
const size_type size()const { return m_v->size(); }
/*! \param v A node. */ bool is_leaf(const node_type& v) const { // node is the last leaf or has no children, so m_bv[v.pos]==1 return (v.pos+1 == m_bv.size()) or m_bv[v.pos+1]; }
//! Returns the number of nodes in the tree. size_type nodes()const { return (m_bv.size()+1)/2; }
//! Returns the number of nodes in the tree. size_type nodes()const { return m_bv.size()+1/2; }