Skip to content

Commit

Permalink
removed deprecated in C++17 std::iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
karasikov committed Sep 11, 2022
1 parent fb94dcb commit 7bdcada
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 23 deletions.
27 changes: 21 additions & 6 deletions include/sdsl/cst_iterators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ namespace sdsl
*/
// TODO: implement operator--
template<class Cst, uint32_t cache_size=128>
class cst_dfs_const_forward_iterator: public std::iterator<std::forward_iterator_tag, typename Cst::node_type>
class cst_dfs_const_forward_iterator
{
public:
typedef typename Cst::node_type value_type;
using iterator_category = std::forward_iterator_tag;
using value_type = typename Cst::node_type;
using difference_type = void;
using pointer = void;
using reference = void;

typedef const value_type const_reference;
typedef typename Cst::size_type size_type;
typedef cst_dfs_const_forward_iterator<Cst> iterator;
Expand Down Expand Up @@ -177,10 +182,15 @@ class cst_dfs_const_forward_iterator: public std::iterator<std::forward_iterator

//! A forward iterator for a bottom up traversal of a suffix tree
template<class Cst>
class cst_bottom_up_const_forward_iterator: public std::iterator<std::forward_iterator_tag, typename Cst::node_type>
class cst_bottom_up_const_forward_iterator
{
public:
typedef typename Cst::node_type value_type;
using iterator_category = std::forward_iterator_tag;
using value_type = typename Cst::node_type;
using difference_type = void;
using pointer = void;
using reference = void;

typedef const value_type const_reference;
typedef typename Cst::size_type size_type;
typedef cst_bottom_up_const_forward_iterator<Cst> iterator;
Expand Down Expand Up @@ -251,10 +261,15 @@ class cst_bottom_up_const_forward_iterator: public std::iterator<std::forward_it
* you should use an external implementation of a queue.
*/
template<class Cst, class Queue = std::queue<typename Cst::node_type> >
class cst_bfs_iterator: public std::iterator<std::forward_iterator_tag, typename Cst::node_type>
class cst_bfs_iterator
{
public:
typedef typename Cst::node_type value_type;
using iterator_category = std::forward_iterator_tag;
using value_type = typename Cst::node_type;
using difference_type = void;
using pointer = void;
using reference = void;

typedef const value_type const_reference;
typedef typename Cst::size_type size_type;
typedef cst_bfs_iterator<Cst, Queue> iterator;
Expand Down
7 changes: 6 additions & 1 deletion include/sdsl/int_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,15 @@ inline void swap(int_vector_reference<bit_vector> x,


template<class t_int_vector>
class int_vector_iterator_base: public std::iterator<std::random_access_iterator_tag, typename t_int_vector::value_type, typename t_int_vector::difference_type>
class int_vector_iterator_base
{
public:
typedef uint64_t size_type;
using iterator_category = std::random_access_iterator_tag;
using value_type = typename t_int_vector::value_type;
using difference_type = typename t_int_vector::difference_type;
using pointer = void;
using reference = void;
protected:
uint8_t m_offset;
uint8_t m_len;
Expand Down
7 changes: 6 additions & 1 deletion include/sdsl/int_vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,17 @@ class int_vector_buffer
}
};

class iterator: public std::iterator<std::random_access_iterator_tag, value_type, difference_type, value_type*, reference>
class iterator
{
private:
int_vector_buffer<t_width>& m_ivb;
uint64_t m_idx = 0;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = int_vector_buffer<t_width>::value_type;
using difference_type = int_vector_buffer<t_width>::difference_type;
using pointer = value_type*;
using reference = int_vector_buffer<t_width>::reference;

iterator() = delete;
iterator(int_vector_buffer<t_width>& ivb, uint64_t idx=0) : m_ivb(ivb), m_idx(idx) {}
Expand Down
9 changes: 7 additions & 2 deletions include/sdsl/iterators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ namespace sdsl
/*! \tparam t_rac Type of random access container.
*/
template<class t_rac>
class random_access_const_iterator: public std::iterator<std::random_access_iterator_tag, typename t_rac::value_type, typename t_rac::difference_type>
class random_access_const_iterator
{
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = typename t_rac::value_type;
using difference_type = typename t_rac::difference_type;
using pointer = void;
using reference = void;

typedef const typename t_rac::value_type const_reference;
typedef typename t_rac::size_type size_type;
typedef random_access_const_iterator<t_rac> iterator;
typedef typename t_rac::difference_type difference_type;

private:
const t_rac* m_rac;// pointer to the random access container
Expand Down
4 changes: 2 additions & 2 deletions include/sdsl/lcp_byte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class lcp_byte
if (m_small_lcp[i]!=255) {
return m_small_lcp[i];
} else {
size_type idx = lower_bound(m_big_lcp_idx.begin(),
m_big_lcp_idx.end(),i)
size_type idx = std::lower_bound(m_big_lcp_idx.begin(),
m_big_lcp_idx.end(),i)
- m_big_lcp_idx.begin();
return m_big_lcp[idx];
}
Expand Down
9 changes: 4 additions & 5 deletions include/sdsl/sd_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,7 @@ class sd_vector
m_size = builder.m_size;
m_wl = builder.m_wl;
m_low.swap(builder.m_low);
if constexpr(std::is_same<hi_bit_vector_type, bit_vector>::value) {
m_high.swap(builder.m_high);
} else {
util::assign(m_high, builder.m_high);
}
util::assign(m_high, builder.m_high);
util::init_support(m_high_1_select, &m_high);
util::init_support(m_high_0_select, &m_high);

Expand Down Expand Up @@ -445,6 +441,9 @@ class sd_vector
}
};

//! Specialized constructor that is a bit more space-efficient than the default.
template<> sd_vector<>::sd_vector(sd_vector_builder& builder);

template<uint8_t t_b>
struct rank_support_sd_trait {
typedef bit_vector::size_type size_type;
Expand Down
9 changes: 7 additions & 2 deletions include/sdsl/suffix_tree_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ namespace sdsl


template <class t_cst>
class cst_node_child_proxy_iterator : public std::iterator<std::forward_iterator_tag, typename t_cst::node_type>
class cst_node_child_proxy_iterator
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = typename t_cst::node_type;
using difference_type = void;
using pointer = void;
using reference = void;

using node_type = typename t_cst::node_type;
using value_type = node_type;
using const_reference = const node_type;
using iterator_type = cst_node_child_proxy_iterator<t_cst>;
private:
Expand Down
8 changes: 5 additions & 3 deletions include/sdsl/wt_gmr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef INCLUDED_SDSL_WT_GMR
#define INCLUDED_SDSL_WT_GMR

#include <algorithm> // for lower_bound

#include <sdsl/bit_vectors.hpp>
#include <sdsl/int_vector.hpp>
#include <sdsl/int_vector_buffer.hpp>
Expand Down Expand Up @@ -520,7 +522,7 @@ class wt_gmr_rs
if (end-begin<50) { // After a short test, this seems to be a good threshold
offset = std::find_if(begin, end, [&val](const decltype(*begin) x) { return x > val; }) - begin;
} else {
offset = lower_bound(begin, end, val+1)-begin;
offset = std::lower_bound(begin, end, val+1)-begin;
}
return (begin-m_e.begin())+offset-ones_before_cblock;
}
Expand Down Expand Up @@ -556,7 +558,7 @@ class wt_gmr_rs
++search_begin;
}
} else {
offset = lower_bound(m_e.begin()+search_begin, m_e.begin()+search_end, val)-m_e.begin();
offset = std::lower_bound(m_e.begin()+search_begin, m_e.begin()+search_end, val)-m_e.begin();
if (offset<search_end) {
if (m_e[offset]==val) {
value_type c = (block-1)/m_blocks;
Expand Down Expand Up @@ -875,7 +877,7 @@ class wt_gmr
if (end-begin<50) { // After a short test, this seems to be a good threshold
c_ones_in_chunk = std::find_if(begin, end, [&val](const decltype(*begin) x) { return x > val; }) - begin;
} else {
c_ones_in_chunk = lower_bound(begin, end, val+1) - begin;
c_ones_in_chunk = std::lower_bound(begin, end, val+1) - begin;
}
return c_ones_before_chunk+c_ones_in_chunk;
}
Expand Down
19 changes: 19 additions & 0 deletions lib/sd_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,23 @@ void sd_vector_builder::swap(sd_vector_builder& sdb)
m_high.swap(sdb.m_high);
}

template<>
sd_vector<>::sd_vector(sd_vector_builder& builder)
{
if (builder.items() < builder.capacity()) {
throw std::runtime_error("sd_vector: the builder is not full.");
} else if (builder.items() > builder.capacity()) {
throw std::runtime_error("sd_vector: builder overflow.");
}

m_size = builder.m_size;
m_wl = builder.m_wl;
m_low.swap(builder.m_low);
m_high.swap(builder.m_high);
util::init_support(m_high_1_select, &m_high);
util::init_support(m_high_0_select, &m_high);

builder = sd_vector_builder();
}

} // end namespace
2 changes: 1 addition & 1 deletion test/inv_perm_support_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class inv_perm_support_test : public ::testing::Test
for (size_t z=0; z < (1ULL<<20); z=(z+1)*2) {
sdsl::int_vector<> iv(z);
sdsl::util::set_to_id(iv);
random_shuffle(iv.begin(), iv.end());
std::random_shuffle(iv.begin(), iv.end());
perms.emplace_back(iv);
}
for (size_t i=0; i<perms.size(); ++i) {
Expand Down

0 comments on commit 7bdcada

Please sign in to comment.