From c9e76950238b90822c18a71ece047cf36dcf0ecc Mon Sep 17 00:00:00 2001 From: alexbowe Date: Fri, 31 Oct 2014 03:06:16 +0900 Subject: [PATCH 1/2] hand-tested WT node ranksel --- include/sdsl/wt_int.hpp | 30 ++++++++++++++++++++++++++++++ include/sdsl/wt_pc.hpp | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/sdsl/wt_int.hpp b/include/sdsl/wt_int.hpp index 1d7b4ca66..aec751414 100644 --- a/include/sdsl/wt_int.hpp +++ b/include/sdsl/wt_int.hpp @@ -166,6 +166,7 @@ class wt_int init_buffers(m_max_level); }; + //! Semi-external constructor /*! \param buf File buffer of the int_vector for which the wt_int should be build. * \param size Size of the prefix of v, which should be indexed. @@ -787,6 +788,35 @@ class wt_int node_type root() const { return node_type(0, m_size, 0, 0); } + + size_type + node_rank1(const node_type & v, size_type i) const { + // Get starting position rank + size_type v_sp_pos = v.offset; + size_type v_sp_rank = m_tree_rank(v_sp_pos); + // TODO: BOUND CHECK: get node size by getting parents left and right children start positions (if any) + return m_tree_rank(v_sp_pos + i) - v_sp_rank; + } + + size_type node_rank0(const node_type & v, size_type i) const { + return i - node_rank1(v, i); + } + + size_type node_select1(const node_type &v, size_type i) const { + size_type v_sp_pos = v.offset; + size_type v_sp_rank1 = m_tree_rank(v_sp_pos); + // TODO: BOUND CHECK: get node size by getting parents left and right children start positions (if any) + return m_tree_select1(i + v_sp_rank1) - v_sp_pos; + } + + size_type node_select0(const node_type &v, size_type i) const { + size_type v_sp_pos = v.offset; + size_type v_sp_rank0 = v_sp_pos - m_tree_rank(v_sp_pos); + // TODO: BOUND CHECK: get node size by getting parents left and right children start positions (if any) + return m_tree_select0(i + v_sp_rank0) - v_sp_pos; + } + + //! Returns the two child nodes of an inner node /*! \param v An inner node of a wavelet tree. diff --git a/include/sdsl/wt_pc.hpp b/include/sdsl/wt_pc.hpp index edfb46f13..4d0770c71 100644 --- a/include/sdsl/wt_pc.hpp +++ b/include/sdsl/wt_pc.hpp @@ -738,6 +738,33 @@ class wt_pc return make_pair(ranges, std::move(res)); } + size_type + node_rank1(const node_type & v, size_type i) const { + // Get starting position rank + size_type v_sp_pos = m_tree.bv_pos(v); + size_type v_sp_rank = m_tree.bv_pos_rank(v); + // TODO: BOUND CHECK: get node size by getting parents left and right children start positions (if any) + return m_bv_rank(v_sp_pos + i) - v_sp_rank; + } + + size_type node_rank0(const node_type & v, size_type i) const { + return i - node_rank1(v, i); + } + + size_type node_select1(const node_type &v, size_type i) const { + auto v_sp_pos = m_tree.bv_pos(v); + auto v_sp_rank1 = m_tree.bv_pos_rank(v); + // TODO: BOUND CHECK: get node size by getting parents left and right children start positions (if any) + return m_bv_select1(i + v_sp_rank1) - v_sp_pos; + } + + size_type node_select0(const node_type &v, size_type i) const { + auto v_sp_pos = m_tree.bv_pos(v); + auto v_sp_rank0 = v_sp_pos - m_tree.bv_pos_rank(v); + // TODO: BOUND CHECK: get node size by getting parents left and right children start positions (if any) + return m_bv_select0(i + v_sp_rank0) - v_sp_pos; + } + //! Returns for a range its left and right child ranges /*! \param v An inner node of an wavelet tree. * \param r A ranges [s,e], such that [s,e] is From 59088bbdc00352022844cccb6f0f812815a22871 Mon Sep 17 00:00:00 2001 From: alexbowe Date: Sat, 1 Nov 2014 17:15:40 +0900 Subject: [PATCH 2/2] Added node access --- include/sdsl/wt_int.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/sdsl/wt_int.hpp b/include/sdsl/wt_int.hpp index aec751414..fd53d5330 100644 --- a/include/sdsl/wt_int.hpp +++ b/include/sdsl/wt_int.hpp @@ -788,7 +788,12 @@ class wt_int node_type root() const { return node_type(0, m_size, 0, 0); } - + + bool node_access(const node_type & v, size_type i) const { + size_type v_sp_pos = v.offset; + return m_tree[v_sp_pos + i]; + } + size_type node_rank1(const node_type & v, size_type i) const { // Get starting position rank