Skip to content

Commit

Permalink
Use pointer to the container for int_vector_buffer iterator (#120)
Browse files Browse the repository at this point in the history
* Use pointer to the container for int_vector_buffer iterator

Using reference member prevents defining assignment operator for the
iterator class of int_vector_buffer. This commit fixes issue
vgteam/sdsl-lite#436.

* Apply suggestions from code review

---------

Co-authored-by: Enrico Seiler <eseiler@users.noreply.github.com>
  • Loading branch information
cartoonist and eseiler authored Sep 11, 2023
1 parent d16ffa2 commit ec4cedc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions include/sdsl/int_vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class int_vector_buffer

typedef typename int_vector<t_width>::difference_type difference_type;
typedef typename int_vector<t_width>::value_type value_type;
typedef typename int_vector<t_width>::size_type size_type;

private:
static_assert(t_width <= 64, "int_vector_buffer: width must be at most 64 bits.");
Expand Down Expand Up @@ -493,7 +494,7 @@ class int_vector_buffer
class iterator
{
private:
int_vector_buffer<t_width> & m_ivb;
int_vector_buffer<t_width> * m_ivb{nullptr};
uint64_t m_idx = 0;

public:
Expand All @@ -504,7 +505,7 @@ class int_vector_buffer
using reference = sdsl::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)
iterator(int_vector_buffer<t_width> & ivb, uint64_t idx = 0) : m_ivb(&ivb), m_idx(idx)
{}

iterator & operator++()
Expand Down Expand Up @@ -535,7 +536,8 @@ class int_vector_buffer

reference operator*() const
{
return m_ivb[m_idx];
assert(m_ivb != nullptr);
return (*m_ivb)[m_idx];
}

iterator & operator+=(difference_type i)
Expand Down Expand Up @@ -568,7 +570,7 @@ class int_vector_buffer

bool operator==(iterator const & it) const
{
return &m_ivb == &(it.m_ivb) and m_idx == it.m_idx;
return m_ivb == it.m_ivb and m_idx == it.m_idx;
}

bool operator!=(iterator const & it) const
Expand Down

0 comments on commit ec4cedc

Please sign in to comment.