18 #ifndef _PASL_DATA_ITERATOR_H_
19 #define _PASL_DATA_ITERATOR_H_
41 template <
class Configuration>
45 using config_type = Configuration;
46 using chunk_pointer =
const typename config_type::chunk_type*;
47 using segment_type =
typename config_type::segment_type;
90 return seg.middle == other.seg.middle
91 && seg.end == other.seg.end;
95 return ! (*
this == other);
138 template <
class Chunkedseq,
class Configuration>
142 using chunkedseq_type = Chunkedseq;
143 using config_type = Configuration;
144 using const_chunkedseq_pointer =
const chunkedseq_type*;
145 using const_chunk_pointer =
const typename config_type::chunk_type*;
174 using cache_type =
typename config_type::middle_cache_type;
185 using chunk_search_type =
typename config_type::chunk_search_type;
187 using size_access =
typename config_type::size_access;
189 const_chunkedseq_pointer seq;
190 const_chunk_pointer cur;
202 std::cout <<
"error" << std::endl;
204 assert(sz <= ssz + 1);
209 template <
class Pred>
211 chunk_search_type chunk_search;
212 assert(size_access::csize(prefix) != seq->size());
213 cur->annotation.prefix.set_cached(prefix);
214 auto res = chunk_search(*cur, meas_fct, prefix, p);
217 seg = cur->segment_by_index(pos - 1);
218 if (seg.middle - seg.begin > cur->size())
219 cur->segment_by_index(pos - 1);
220 assert(seg.middle - seg.begin <= cur->size());
226 template <
class Pred>
229 if (seq->is_buffer(cur))
231 prefix = seq->search_for_chunk(p, prefix, found, cur);
233 prefix = chunk_search_by(p, prefix);
236 assert(size_access::csize(prefix) == seq->size());
237 cur = seq->get_chunk_containing_last_item();
240 size_access::size(m) = seq->size() - sz_cur;
241 cur->annotation.prefix.set_cached(m);
243 seg.begin = seg.end =
nullptr;
245 seg = cur->segment_by_index(sz_cur - 1);
246 seg.middle = seg.end;
252 template <
class Pred>
254 return chunkedseq_search_by(p, algebra_type::identity());
259 it.search_by_one_based_index(sz);
268 search_by_one_based_index(orig_sz + n);
271 assert(
size() == orig_sz + n);
281 search_by_one_based_index(orig_sz - n);
284 assert(
size() == orig_sz - n);
290 if (seg.middle == seg.end) {
291 if (seg.middle == seg.begin)
293 return c->index_of_pointer(seg.middle - 1) + 1;
295 return c->index_of_pointer(seg.middle);
300 measured_type prefix_of_chunk = cur->annotation.prefix.template get_cached<measured_type>();
301 size_type nb_items_before_chunk = size_access::csize(prefix_of_chunk);
302 size_type nb_items_before_seg_middle = nb_before_middle(cur, seg);
303 return nb_items_before_chunk + nb_items_before_seg_middle;
306 void search_by_one_based_index(
size_type i) {
307 using predicate_type = itemsearch::less_than_by_position<measured_type, size_type, size_access>;
308 predicate_type p(i - 1);
309 chunkedseq_search_by(p);
312 assert(sz <= ssz + 1);
316 void search_by_zero_based_index(
size_type i) {
317 search_by_one_based_index(i + 1);
325 : seq(seq), cur(nullptr), meas_fct(meas) {
326 search_by_one_based_index(1);
329 search_by_one_based_index(1);
333 search_by_one_based_index(seq->size() + 1);
348 assert(seq == other.seq);
349 bool eq = seg.middle == other.seg.middle
350 && seg.end == other.seg.end;
354 assert(eq ? sz == sz_other : sz != sz_other);
360 return ! (*
this == other);
369 return increment_by(1);
381 return decrement_by(1);
399 return increment_by(n);
403 return new_iterator_at(
size() + other.
size());
407 return new_iterator_at(
size() + n);
411 return decrement_by(n);
421 return new_iterator_at(sz - n);
460 return size_of_prefix() + 1;
463 template <
class Pred>
466 return p(size_access::cclient(m));
468 chunkedseq_search_by(q, algebra_type::identity());
typename config_type::difference_type difference_type
bool operator>=(const self_type &other) const
segment_type get_segment() const
typename cache_type::measured_type measured_type
typename config_type::value_type value_type
typename config_type::value_type value_type
reference operator*() const
typename cache_type::algebra_type algebra_type
bool operator==(const self_type &other) const
self_type & operator-=(const size_type n)
self_type operator+(const self_type &other) const
bool operator==(const self_type &other) const
bidirectional< config_type > self_type
bool operator<=(const self_type &other) const
self_type operator+(const size_type n) const
self_type operator--(int)
const value_type & const_reference
segment_type get_segment() const
typename config_type::segment_type segment_type
difference_type operator-(const self_type &other) const
std::random_access_iterator_tag iterator_category
random_access< chunkedseq_type, config_type > self_type
bool operator>(const self_type &other) const
void search_by(const Pred &p)
self_type operator++(int)
Routines for finding an item in a container via binary search.
bool operator<(const self_type &other) const
typename cache_type::measure_type measure_type
reference operator*() const
bidirectional(chunk_pointer p)
bool operator!=(const self_type &other) const
typename config_type::size_type size_type
reference operator[](const size_type n) const
self_type & operator+=(const size_type n)
bool operator!=(const self_type &other) const
self_type operator--(int)
const value_type * const_pointer
self_type operator++(int)
typename config_type::difference_type difference_type
size_type size() const
Returns the number of items preceding and including the item pointed to by the iterator.
typename config_type::middle_cache_type cache_type
enum{begin, end} position_type
random_access(const_chunkedseq_pointer seq, const measure_type &meas, position_type pos)
std::bidirectional_iterator_tag iterator_category
self_type operator-(const size_type n) const