SDSL 3.0.3
Succinct Data Structure Library
Loading...
Searching...
No Matches
iterators.hpp
Go to the documentation of this file.
1// Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
2// Please see the AUTHORS file for details. Use of this source code is governed
3// by a BSD license that can be found in the LICENSE file.
8#ifndef INCLUDED_SDSL_ITERATORS
9#define INCLUDED_SDSL_ITERATORS
10
11#include <iterator>
12#include <type_traits> // std::invoke_result_t
13
14#include <sdsl/int_vector.hpp>
15
16namespace sdsl
17{
18
20
22template <class t_rac>
24{
25public:
26 using iterator_category = std::random_access_iterator_tag;
27 using value_type = typename t_rac::value_type;
28 using difference_type = typename t_rac::difference_type;
31
32 typedef const typename t_rac::value_type const_reference;
33 typedef typename t_rac::size_type size_type;
35
36private:
37 t_rac const * m_rac; // pointer to the random access container
38 typename t_rac::size_type m_idx;
39
40 template <class t_RAC>
43
44public:
46 random_access_const_iterator(t_rac const * rac, size_type idx = 0) : m_rac(rac), m_idx(idx)
47 {}
48
51 {
52 return (*m_rac)[m_idx];
53 }
54
57 {
58 ++m_idx;
59 return *this;
60 }
61
64 {
66 ++(*this);
67 return it;
68 }
69
72 {
73 --m_idx;
74 return *this;
75 }
76
79 {
81 --(*this);
82 return it;
83 }
84
86 {
87 if (i < 0)
88 return *this -= (-i);
89 m_idx += i;
90 return *this;
91 }
92
94 {
95 if (i < 0)
96 return *this += (-i);
97 m_idx -= i;
98 return *this;
99 }
100
102 {
103 iterator it = *this;
104 return it += i;
105 }
106
108 {
109 iterator it = *this;
110 return it -= i;
111 }
112
114 {
115 return *(*this + i);
116 }
117
118 bool operator==(iterator const & it) const
119 {
120 return it.m_rac == m_rac && it.m_idx == m_idx;
121 }
122
123 bool operator!=(iterator const & it) const
124 {
125 return !(*this == it);
126 }
127
128 bool operator<(iterator const & it) const
129 {
130 return m_idx < it.m_idx;
131 }
132
133 bool operator>(iterator const & it) const
134 {
135 return m_idx > it.m_idx;
136 }
137
138 bool operator>=(iterator const & it) const
139 {
140 return !(*this < it);
141 }
142
143 bool operator<=(iterator const & it) const
144 {
145 return !(*this > it);
146 }
147};
148
149template <class t_rac>
156
157template <class t_rac>
163
164template <typename t_F>
166{
169 typedef typename std::invoke_result_t<t_F, size_type> value_type;
171
172 t_F f;
174
178
180 {
181 return f(i);
182 }
183
185 {
186 return m_size;
187 }
188
190 {
191 return iterator_type(this, 0);
192 }
193
195 {
196 return iterator_type(this, size());
197 }
198};
199
200} // end namespace sdsl
201#endif
int_vector_size_type size_type
ptrdiff_t difference_type
Generic iterator for a random access container.
Definition iterators.hpp:24
random_access_const_iterator< bit_vector_il > iterator
Definition iterators.hpp:34
friend random_access_const_iterator< t_RAC >::difference_type operator-(random_access_const_iterator< t_RAC > const &x, random_access_const_iterator< t_RAC > const &y)
iterator operator++(int)
Postfix increment of the Iterator.
Definition iterators.hpp:63
random_access_const_iterator(t_rac const *rac, size_type idx=0)
Constructor.
Definition iterators.hpp:46
bool operator!=(iterator const &it) const
iterator & operator--()
Prefix decrement of the Iterator.
Definition iterators.hpp:71
typename bit_vector_il::difference_type difference_type
Definition iterators.hpp:28
std::random_access_iterator_tag iterator_category
Definition iterators.hpp:26
iterator & operator+=(difference_type i)
Definition iterators.hpp:85
bool operator>(iterator const &it) const
bool operator==(iterator const &it) const
bool operator<(iterator const &it) const
bool operator<=(iterator const &it) const
iterator & operator-=(difference_type i)
Definition iterators.hpp:93
bool operator>=(iterator const &it) const
iterator & operator++()
Prefix increment of the Iterator.
Definition iterators.hpp:56
iterator operator--(int)
Postfix decrement of the Iterator.
Definition iterators.hpp:78
iterator operator+(difference_type i) const
const_reference operator[](difference_type i) const
const_reference operator*() const
Dereference operator for the Iterator.
Definition iterators.hpp:50
typename bit_vector_il::value_type value_type
Definition iterators.hpp:27
const bit_vector_il::value_type const_reference
Definition iterators.hpp:32
iterator operator-(difference_type i) const
int_vector.hpp contains the sdsl::int_vector class.
Namespace for the succinct data structure library.
int_vector_iterator< t_int_vector > operator+(typename int_vector_iterator< t_int_vector >::difference_type n, int_vector_iterator< t_int_vector > const &it)
int_vector_const_iterator< t_int_vector >::difference_type operator-(int_vector_const_iterator< t_int_vector > const &x, int_vector_const_iterator< t_int_vector > const &y)
iterator_type begin() const
int_vector ::difference_type difference_type
random_access_const_iterator< random_access_container > iterator_type
std::invoke_result_t< t_F, size_type > value_type
int_vector ::size_type size_type
iterator_type end() const
value_type operator[](size_type i) const
random_access_container(t_F ff, size_type size)