From 1a3244bd8fbc98c9ea809716c9e8b0507d397cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20K=C3=B6ppl?= Date: Tue, 15 Nov 2016 09:29:28 +0100 Subject: [PATCH 1/3] added level ancestor to bp_support_sada --- include/sdsl/bp_support_sada.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/sdsl/bp_support_sada.hpp b/include/sdsl/bp_support_sada.hpp index ff9f3ae31..1ef1c8426 100644 --- a/include/sdsl/bp_support_sada.hpp +++ b/include/sdsl/bp_support_sada.hpp @@ -212,6 +212,21 @@ class bp_support_sada std::cout<< std::endl; } + //! Returns the level ancestor of the node i. + /*! \param i The index of a parenthesis (i.e., a node). + * \param d The level, i.e., which node to select on the path from the node i up to the root. + * The level d = 0 will return the node itself, d = 1 will return its parent, and so on. + */ + size_type level_anc(size_type i, size_type d)const + { + assert(i < m_size); + size_type bwd_ex = bwd_excess(i,-d-1); + if (bwd_ex == size()) + return size(); + else + return bwd_ex+1; + } + //! Calculate the min parenthesis \f$j>i\f$ with \f$excess(j)=excess(i)+rel\f$ /*! \param i The index of a parenthesis in the supported sequence. * \param rel The excess difference to the excess value of parentheses \f$i\f$. From 538985e5bb5cbb943f8488d1dc7887a1d5d23b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20K=C3=B6ppl?= Date: Thu, 17 Nov 2016 17:00:40 +0100 Subject: [PATCH 2/3] moved level_anc to public --- include/sdsl/bp_support_sada.hpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/include/sdsl/bp_support_sada.hpp b/include/sdsl/bp_support_sada.hpp index 1ef1c8426..1a8715636 100644 --- a/include/sdsl/bp_support_sada.hpp +++ b/include/sdsl/bp_support_sada.hpp @@ -212,20 +212,6 @@ class bp_support_sada std::cout<< std::endl; } - //! Returns the level ancestor of the node i. - /*! \param i The index of a parenthesis (i.e., a node). - * \param d The level, i.e., which node to select on the path from the node i up to the root. - * The level d = 0 will return the node itself, d = 1 will return its parent, and so on. - */ - size_type level_anc(size_type i, size_type d)const - { - assert(i < m_size); - size_type bwd_ex = bwd_excess(i,-d-1); - if (bwd_ex == size()) - return size(); - else - return bwd_ex+1; - } //! Calculate the min parenthesis \f$j>i\f$ with \f$excess(j)=excess(i)+rel\f$ /*! \param i The index of a parenthesis in the supported sequence. @@ -892,7 +878,22 @@ class bp_support_sada } } - /*! The size of the supported balanced parentheses sequence. + //! Returns the level ancestor of the node i. + /*! \param i The index of a parenthesis (i.e., a node). + * \param d The level, i.e., which node to select on the path from the node i up to the root. + * The level d = 0 will return the node itself, d = 1 will return its parent, and so on. + */ + size_type level_anc(size_type i, size_type d)const + { + assert(i < m_size); + size_type bwd_ex = bwd_excess(i,-d-1); + if (bwd_ex == size()) + return size(); + else + return bwd_ex+1; + } + + /*! The size of the supported balanced parentheses sequence. * \return the size of the supported balanced parentheses sequence. */ size_type size() const From 25fdeb746002c8e07a9eeb37826e1a3a5a81a58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20K=C3=B6ppl?= Date: Thu, 17 Nov 2016 17:01:03 +0100 Subject: [PATCH 3/3] added level_anc test case --- test/cst_byte_test.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/cst_byte_test.cpp b/test/cst_byte_test.cpp index 31fc3b971..fe5edc610 100644 --- a/test/cst_byte_test.cpp +++ b/test/cst_byte_test.cpp @@ -45,6 +45,29 @@ cst_sct3<>, cst_sct3, lcp_bitcompressed<> > > Implementations; + +template +class cst_byte_test_sada : public ::testing::Test { }; +typedef Types> sadaBPImpl; +TYPED_TEST_CASE(cst_byte_test_sada, sadaBPImpl); +TYPED_TEST(cst_byte_test_sada, create_and_store) +{ + TypeParam cst; + typedef typename TypeParam::node_type node_t; + ASSERT_TRUE(load_from_file(cst, temp_file)); + for(const node_t& node : cst) { + node_t ancestor = node; + size_t level = 0; + while(ancestor != cst.root()) { + const node_t bpa = cst.bp_support.level_anc(node, level); + ASSERT_EQ(bpa, ancestor); + ancestor = cst.parent(ancestor); + ++level; + } + } +} + + TYPED_TEST_CASE(cst_byte_test, Implementations);