16 #ifndef _PASL_DATA_CHUNK_H_
17 #define _PASL_DATA_CHUNK_H_
86 class Fixed_capacity_queue,
88 class Annotation=annotation::annotation_builder<>,
89 class Pointer_deleter1=Dummy_pointer_deleter,
90 class Pointer_deep_copier1=Dummy_pointer_deep_copier,
91 class Size_access=itemsearch::no_size_access
122 using size_type =
typename cache_type::size_type;
129 static constexpr
int capacity = queue_type::capacity;
149 cached = algebra_type::combine(m, cached);
153 cached = algebra_type::combine(cached, m);
157 incr_front(algebra_type::inverse(m));
161 incr_back(algebra_type::inverse(m));
170 res = algebra_type::combine(res, meas(lo, hi));
176 return measure_range(meas, 0,
size());
185 incr_front(measure_range(meas, 0, hi));
192 incr_back(measure_range(meas, lo,
size()));
196 decr_front(measure_range(meas, 0, hi));
200 decr_back(measure_range(meas, lo,
size()));
210 cached = algebra_type::identity();
214 : cached(other.cached), items(other.items), annotation(other.annotation) {
215 if (Pointer_deep_copier1::should_use)
222 if (Pointer_deleter1::should_use)
224 Pointer_deleter1::dealloc(v);
238 return items.empty();
242 return items.partial();
264 return items.front();
272 items.frontn(xs, (
int)nb);
276 items.backn(xs, (
int)nb);
283 template <
class Body>
285 items.for_each(body);
288 template <
class Body>
294 template <
class Body>
296 items.for_each_segment(
int(lo),
int(hi), body);
300 return items.segment_by_index(
int(i));
304 return items.index_of_pointer(p);
324 if (algebra_type::has_inverse)
327 if (! algebra_type::has_inverse)
334 if (algebra_type::has_inverse)
337 if (! algebra_type::has_inverse)
363 items.pushn_front(xs, (
int)nb);
364 incr_frontn(meas, nb);
369 items.pushn_back(xs, (
int)nb);
370 incr_backn(meas,
int(nb_before));
373 template <
class Body>
376 items.pushn_back(body, (
int)nb);
377 incr_backn(meas,
int(nb_before));
381 if (algebra_type::has_inverse)
382 decr_frontn(meas, nb);
383 items.popn_front(
int(nb));
384 if (! algebra_type::has_inverse)
389 if (algebra_type::has_inverse) {
391 decr_backn(meas, nb_before);
393 items.popn_back((
int)nb);
394 if (! algebra_type::has_inverse)
400 if (algebra_type::has_inverse)
401 decr_frontn(meas, nb);
402 items.popn_front(xs, (
int)nb);
403 if (! algebra_type::has_inverse)
409 if (algebra_type::has_inverse) {
411 decr_backn(meas, nb_before);
413 items.popn_back(xs, (
int)nb);
414 if (! algebra_type::has_inverse)
418 template <
class Consumer,
bool should_consume>
422 if (should_consume && sz > 0 && nb > 0) {
427 cons(seg.middle, seg.middle + nb);
430 cons(seg2.middle, seg2.middle + (nb - sz_seg));
431 cons(seg.middle, seg.middle + sz_seg);
437 template <
class Consumer,
bool should_consume>
441 if (should_consume && sz > 0 && nb > 0) {
444 size_type sz_seg = seg.middle - seg.begin + 1;
446 cons(seg.begin, seg.middle + 1);
449 cons(seg2.begin, seg2.end);
450 cons(seg.begin, seg.middle + 1);
460 if (algebra_type::has_inverse)
462 items.transfer_from_back_to_front(target.
items, (
int)nb);
463 if (! algebra_type::has_inverse)
465 target.incr_front(delta);
470 if (algebra_type::has_inverse)
472 items.transfer_from_front_to_back(target.
items, (
int)nb);
473 if (! algebra_type::has_inverse)
475 target.incr_back(delta);
483 template <
class Pred,
class Search,
class Search_measure>
486 const Search& search,
487 const Search_measure& search_meas,
488 typename Search::measured_type prefix,
492 auto res = search(*
this, search_meas, prefix, p);
516 template <
class Pred,
class Search,
class Search_measure>
519 const Search& search,
520 const Search_measure& search_meas,
521 typename Search::measured_type prefix,
525 prefix =
split(meas, p, search, search_meas, prefix, found, x, other);
531 template <
class Pred,
class Search,
class Search_measure>
534 const Search& search,
535 const Search_measure& search_meas,
536 typename Search::measured_type prefix,
539 prefix =
split(meas, p, search, search_meas, prefix, x, other);
544 template <
class Pred>
551 return split(meas, p, search, meas, prefix, x, other);
554 template <
class Pred>
560 return split(meas, p, search, meas, prefix, other);
568 items.popn_back(
int(
size()));
569 cached = algebra_type::identity();
573 items.swap(other.
items);
574 cache_type::swap(cached, other.
cached);
579 cached = measure(meas);
585 if (Size_access::enable_index_optimization)
586 assert(Size_access::csize(measure(meas)) == Size_access::csize(cached));
void popn_front(const measure_type &meas, const Consumer &cons, size_type nb)
size_type index_of_pointer(const value_type *p) const
value_type & front() const
void for_each(const Body &body) const
value_type pop_back(const measure_type &meas)
queue_type items
queue structure to contain the items of the chunk
value_type & back() const
static void dealloc(Item x)
static Item * copy(Item *x)
Search::measured_type split(const measure_type &meas, const Pred &p, const Search &search, const Search_measure &search_meas, typename Search::measured_type prefix, bool &found, value_type &x, self_type &other)
void reset_cache(const measure_type &meas)
typename cache_type::algebra_type algebra_type
value_type pop_front(const measure_type &meas)
void for_each_segment(const Body &body) const
value_type & operator[](size_type ix) const
void popn_front(const measure_type &meas, value_type *xs, size_type nb)
static constexpr bool should_use
void popn_back(const measure_type &meas, value_type *xs, size_type nb)
Fixed-capacity array along with cached measurement of array contents.
Search::measured_type split(const measure_type &meas, const Pred &p, const Search &search, const Search_measure &search_meas, typename Search::measured_type prefix, value_type &x, self_type &other)
Defines an interface for attaching data to nodes in the underlying tree structure of the chunked sequ...
static void dealloc(Item *x)
chunk(const self_type &other)
void for_each_segment(size_type lo, size_type hi, const Body &body) const
void copy(typename Alloc::pointer destination, typename Alloc::const_pointer source, typename Alloc::size_type num)
Polymorphic array copy.
void swap(self_type &other)
void transfer_from_front_to_back(const measure_type &meas, chunk &target, size_type nb)
void popn_back(const measure_type &meas, const Consumer &cons, size_type nb)
void popn_back(const measure_type &meas, size_type nb)
typename cache_type::size_type size_type
measured_type split(const measure_type &meas, const Pred &p, measured_type prefix, value_type &x, self_type &other)
measured_type split(const measure_type &meas, const Pred &p, measured_type prefix, self_type &other)
typename queue_type::value_type value_type
typename cache_type::measured_type measured_type
void popn_front(const measure_type &meas, size_type nb)
static constexpr bool should_use
const value_type * const_pointer
Routines for finding an item in a container via binary search.
segment_type segment_by_index(size_type i) const
void check_cached(const measure_type &meas) const
void push_front(const measure_type &meas, const value_type &x)
void pushn_back(const measure_type &meas, const value_type *xs, size_type nb)
Search::measured_type split(const measure_type &meas, const Pred &p, const Search &search, const Search_measure &search_meas, typename Search::measured_type prefix, self_type &other)
void transfer_from_back_to_front(const measure_type &meas, chunk &target, size_type nb)
void pushn_back(const measure_type &meas, const Body &body, size_type nb)
void concat(const measure_type &meas, self_type &other)
const value_type & const_reference
measured_type get_cached() const
Fixed_capacity_queue queue_type
annotation_type annotation_type
typename queue_type::segment_type segment_type
void frontn(value_type *xs, size_type nb)
static constexpr bool should_use
measured_type cached
cached measurement of the items contained in the chunk
annotation_type annotation
annotation value to be attached to the chunk
static constexpr bool should_use
void pushn_front(const measure_type &meas, const value_type *xs, size_type nb)
void push_back(const measure_type &meas, const value_type &x)
static constexpr int capacity
capacity in number of items
typename cache_type::measure_type measure_type
void backn(value_type *xs, size_type nb)