8#include "acme/prototype/mathematics/numeric.h"
12template <
typename TYPE,
typename ARG_TYPE >
14 public ::block_range < TYPE * >
19 using BASE_RANGE = ::block_range<TYPE *>;
21 using BASE_RAW_RANGE = ::range<TYPE *>;
22 using BASE_TYPE = TYPE;
23 using BASE_PAYLOAD = TYPE;
25 using BASE_RANGE::BASE_RANGE;
28 constexpr bool array_range_ok()
const {
return true; }
31 ::collection::count size()
const {
return this->m_end - this->m_begin; }
32 ::collection::count get_count()
const {
return this->size(); }
35 inline ::collection::index get_lower_bound(::collection::index i = 0)
const;
36 inline ::collection::index get_middle_index(::collection::index i = 0)
const;
37 inline ::collection::index get_upper_bound(::collection::index i = -1)
const;
38 inline ::collection::index lower_bound(::collection::index i = 0)
const {
return this->get_lower_bound(i); }
39 inline ::collection::index upper_bound(::collection::index i = -1)
const {
return this->get_upper_bound(i); }
40 inline ::collection::index first_index(::collection::index i = 0)
const {
return this->lower_bound(i); }
41 inline ::collection::index middle_index(::collection::index i = 0)
const {
return this->get_middle_index(i); }
42 inline ::collection::index last_index(::collection::index i = -1)
const {
return this->get_upper_bound(i); }
43 inline bool bounds(::collection::index i)
const;
44 inline bool contains_index(::collection::index i)
const {
return bounds(i); }
47 inline bool prepare_first_last(::collection::index& first, ::collection::index& last)
const;
48 inline bool prepare_first_in_count_last_out(::collection::index& first, ::collection::count& inCountLastOut)
const;
51 inline const TYPE *ptr_at(::collection::index nIndex)
const {
return this->m_begin + nIndex; }
52 inline TYPE *ptr_at(::collection::index nIndex) {
return this->m_begin + nIndex; }
54 inline const TYPE &element_at(::collection::index nIndex)
const;
55 inline TYPE &element_at(::collection::index nIndex);
57 inline TYPE &first(::collection::index n = 0);
58 inline const TYPE &first(::collection::index n = 0)
const;
60 inline TYPE &last(::collection::index n = -1);
61 inline const TYPE &last(::collection::index n = -1)
const;
63 inline TYPE &middle(::collection::index n = 0);
64 inline const TYPE &middle(::collection::index n = 0)
const;
67 TYPE &operator[](::collection::index i) {
return this->m_begin[i]; }
68 const TYPE &operator[](::collection::index i)
const {
return this->m_begin[i]; }
71 auto &payloads() {
return *
this; }
72 auto &payloads()
const {
return *
this; }
440template<
typename TYPE,
typename ARG_TYPE>
441inline ::collection::index array_range<TYPE, ARG_TYPE>::get_lower_bound(::collection::index i)
const
443 return i < this->size() ? i : -1;
446template<
typename TYPE,
typename ARG_TYPE>
447inline ::collection::index
448array_range<TYPE, ARG_TYPE>::get_middle_index(::collection::index iIndex)
const
450 return this->size() / 2 + iIndex;
454template<
typename TYPE,
typename ARG_TYPE>
455inline ::collection::index
456array_range<TYPE, ARG_TYPE>::get_upper_bound(::collection::index iIndex)
const
458 return this->size() + iIndex;
461template<
typename TYPE,
typename ARG_TYPE>
462inline bool array_range<TYPE, ARG_TYPE>::bounds(::collection::index i)
const
464 return i >= 0 && i < this->size();
469template<
typename TYPE,
typename ARG_TYPE>
470bool array_range<TYPE, ARG_TYPE>::prepare_first_last(::collection::index& first,
471 ::collection::index& last)
const
477 first += this->array_get_count();
484 last += this->array_get_count();
488 return last >= first;
492template<
typename TYPE,
typename ARG_TYPE>
493bool array_range<TYPE, ARG_TYPE >::prepare_first_in_count_last_out(
494 ::collection::index& first, ::collection::count& in_count_out_last)
const
500 first += this->array_get_count();
511 if (in_count_out_last < 0)
514 in_count_out_last += this->array_get_count();
520 in_count_out_last = first + in_count_out_last - 1;
524 return in_count_out_last >= first;
529 template<
typename TYPE,
typename ARG_TYPE>
530inline const TYPE &array_range<TYPE, ARG_TYPE>::element_at(::collection::index nIndex)
const
533 ASSERT(nIndex >= 0 && nIndex < this->size());
535 return this->m_begin[nIndex];
540 template<
typename TYPE,
typename ARG_TYPE>
541 inline TYPE &array_range<TYPE, ARG_TYPE>::element_at(::collection::index nIndex)
544 ASSERT(nIndex >= 0 && nIndex < this->size());
546 return this->m_begin[nIndex];
551template<
typename TYPE,
typename ARG_TYPE>
552inline const TYPE &array_range<TYPE, ARG_TYPE>::first(::collection::index nIndex)
const
555 return this->element_at(nIndex);
559template<
typename TYPE,
typename ARG_TYPE>
560inline TYPE &array_range<TYPE, ARG_TYPE>::first(::collection::index nIndex)
563 return this->element_at(nIndex);
567template<
typename TYPE,
typename ARG_TYPE>
568inline const TYPE &array_range<TYPE, ARG_TYPE>::last(::collection::index i)
const
571 return element_at(this->get_upper_bound(i));
575template<
typename TYPE,
typename ARG_TYPE>
576inline TYPE &array_range<TYPE, ARG_TYPE>::last(::collection::index i)
579 return element_at(this->get_upper_bound(i));
583template<
typename TYPE,
typename ARG_TYPE>
584inline const TYPE &array_range<TYPE, ARG_TYPE>::middle(::collection::index i)
const
587 return element_at(this->get_middle_index(i));
591template<
typename TYPE,
typename ARG_TYPE>
592inline TYPE &array_range<TYPE, ARG_TYPE>::middle(::collection::index i)
595 return element_at(this->get_middle_index(i));
Definition array_range.h:15