5#include "comparable_eq_array.h"
6#include "comparable_array.h"
7#include "comparable_raw_array.h"
8#include "acme/prototype/prototype/compare_predicate.h"
9#include "acme/prototype/prototype/make_particle.h"
10#include "acme/prototype/mathematics/numeric.h"
13template <
typename ARG_TYPE >
14::collection::index numeric_compare(ARG_TYPE t1, ARG_TYPE t2)
16 typename ::non_reference < ARG_TYPE >::TYPE t = t1 - t2;
17 if(t >
::numeric_info< typename ::non_reference < ARG_TYPE >::TYPE >::null())
19 else if(t <
::numeric_info < typename ::non_reference < ARG_TYPE >::TYPE >::null())
34template <
typename TYPE, enum_type t_etypeContainer >
36 public comparable_raw_array_base < TYPE, TYPE, ::typed::nodef < TYPE >, ::heap::typed_memory < TYPE, ::heap::e_memory_array >, t_etypeContainer >
41 using BASE_ARRAY = comparable_raw_array_base < TYPE, TYPE, ::typed::nodef < TYPE >, ::heap::typed_memory < TYPE, ::heap::e_memory_array >, t_etypeContainer >;
42 using BASE_TYPE = TYPE;
43 using BASE_ARG_TYPE =
const TYPE &;
46 using BASE_ARRAY::BASE_ARRAY;
47 using BASE_ARRAY::operator =;
83 ::collection::index find_first_maximum_value()
const;
84 const TYPE & get_maximum_value()
const;
85 ::collection::index find_first_minimum_value()
const;
86 const TYPE & get_minimum_value()
const;
89 template < prototype_
integral INTEGRAL >
90 INTEGRAL & mask(INTEGRAL & i)
95 for(
auto number : *
this)
110 TYPE pop_max_last_add_up(TYPE tLastAddUp);
112 TYPE get_sum(::collection::index first = 0, ::collection::count in_count_out_last = -1)
const
115 this->prepare_first_in_count_last_out(first, in_count_out_last);
117 TYPE t = ::numeric_info < TYPE >:: null();
119 for(::collection::index i = first; i <= in_count_out_last; i++)
124 t += this->element_at(i);
136 void CopySorted(
const numeric_array_base & array,
const TYPE & tOffset,
const TYPE & tMin);
148 TYPE simple_total_mean();
150 void set(
const TYPE & t, ::collection::index iStart = 0, ::collection::index iEnd = -1);
172 ::collection::count iCompare = this->get_size() - a.get_size();
177 return ::numeric::sign(iCompare);
182 for(::collection::index i = 0; i < this->get_size(); i++)
185 t = this->element_at(i) - a[i];
190 return ::numeric::sign(t);
228 bool is_any_set()
const
231 return this->predicate_contains([](
auto number) {
return number != (TYPE)0; });
240template <
typename TYPE, ::enum_type t_etypeContainer >
241class unique_number_sort_array :
245 unique_number_sort_array();
246 unique_number_sort_array(
const unique_number_sort_array & array);
248 ::collection::index add(
const TYPE & newElement)
250 ::collection::index iFind = 0;
251 if(find(newElement, iFind))
257 this->insert_at(iFind, newElement);
262 bool find(
const TYPE &t, ::collection::index & find)
const
264 ::collection::index iL = find;
265 ::collection::index iU = this->get_upper_bound();
268 find = (iL + iU) / 2;
269 TYPE tCmp = t - this->element_at(find);
270 if(tCmp == numeric_info < TYPE > :: null ())
274 else if(tCmp > numeric_info < TYPE >::null())
283 for(; find < this->get_size(); find++)
285 TYPE tCmp = t - this->element_at(find);
286 if(tCmp == numeric_info < TYPE >::null())
290 else if(tCmp < numeric_info < TYPE >::null())
543template <
typename TYPE, ::enum_type t_etypeContainer >
544numeric_array_base < TYPE, t_etypeContainer > numeric_array_base < TYPE, t_etypeContainer >::unique()
const
547 numeric_array_base < TYPE, t_etypeContainer > a;
549 for(::i32 i = 0; i < this->get_count(); i++)
551 a.add_unique(this->element_at(i));
558template <
typename TYPE, ::enum_type t_etypeContainer >
559void numeric_array_base < TYPE, t_etypeContainer >::unique()
562 numeric_array_base < TYPE, t_etypeContainer > a;
564 for(::i32 i = 0; i < this->get_count(); i++)
566 a.add_unique(this->element_at(i));
577template <
typename TYPE, ::enum_type t_etypeContainer >
578::collection::index numeric_array_base < TYPE, t_etypeContainer >::
581 ::collection::count iMinSize = minimum(array1.get_size(), this->get_size());
582 ::collection::index i = 0;
587 return this->get_size() - array1.get_size();
589 if(this->element_at(i) > array1.element_at(i))
591 else if(this->element_at(i) < array1.element_at(i))
597template <
typename TYPE, ::enum_type t_etypeContainer >
598void numeric_array_base < TYPE, t_etypeContainer >::CopySorted(
605 ::collection::index i;
606 TYPE tStart = tMin - tOffset;
607 this->set_size(a.get_size());
609 for(i = 0; i < a.get_size()
610 && a.get_at(i) <= tStart; i++)
612 this->set_at(i, tMin);
614 for(; i < a.get_size(); i++)
616 t = a.get_at(i) + tOffset;
622template <
typename TYPE, ::enum_type t_etypeContainer >
623void numeric_array_base < TYPE, t_etypeContainer >::Diff(
624const numeric_array_base < TYPE, t_etypeContainer > & array1,
625const numeric_array_base < TYPE, t_etypeContainer > & array2)
627 ASSERT(array1.get_size() == array2.get_size());
628 ::collection::index i;
629 this->set_size(array1.get_size());
631 for(i = 0; i < array1.get_size(); i++)
633 t = array1.get_at(i) - array2.get_at(i);
638template <
typename TYPE, ::enum_type t_etypeContainer >
639void numeric_array_base < TYPE, t_etypeContainer >::ElementDiff(
643 ::collection::index i;
646 this->set_size(a.get_size());
650 for(i = 1; i < a.get_size(); i++)
654 this->set_at(i - 1, it);
658 this->set_at(i - 1, it);
663template <
typename TYPE, ::enum_type t_etypeContainer >
664::collection::index numeric_array_base < TYPE, t_etypeContainer >::find_first_maximum_value()
const
667 TYPE tMax = this->element_at(0);
669 ::collection::index iFind = 0;
671 for(::collection::index i = 1; i < this->get_size(); i++)
674 if (this->element_at(i) > tMax)
679 tMax = this->element_at(i);
690template <
typename TYPE, ::enum_type t_etypeContainer >
691const TYPE & numeric_array_base < TYPE, t_etypeContainer >::
692get_maximum_value()
const
694 ASSERT(this->get_size() > 0);
695 return this->element_at(find_first_maximum_value());
698template <
typename TYPE, ::enum_type t_etypeContainer >
699::collection::index numeric_array_base < TYPE, t_etypeContainer >::find_first_minimum_value()
const
702 TYPE tMin = this->element_at(0);
704 ::collection::index iFind = 0;
706 for (::collection::index i = 1; i < this->get_size(); i++)
709 if (this->element_at(i) < tMin)
714 tMin = this->element_at(i);
725template <
typename TYPE, ::enum_type t_etypeContainer >
726const TYPE & numeric_array_base < TYPE, t_etypeContainer >::
727get_minimum_value()
const
729 ASSERT(this->get_size() > 0);
730 return this->element_at(find_first_minimum_value());
733template <
typename INTEGER >
734inline INTEGER get_integer_mean(
const INTEGER * p, ::collection::count N)
738 ::collection::count c = N;
745 ::i32 b = (::i32) (a % N);
758 ::i32 b = (::i32) ((-a) % N);
772 return (::i32) (x + y / N);
777template < prototype_
integral INTEGRAL >
778inline INTEGRAL simple_total_mean(
const INTEGRAL * p, ::collection::count N)
783 ::collection::count c = N;
796 return (INTEGRAL) (i / N);
800template < prototype_
floating FLOATING >
801inline FLOATING simple_total_mean(
const FLOATING * p, ::collection::count N)
806 ::collection::count c = N;
819 return (FLOATING)(d / (::f64) N);
823inline ::i32 get_mean(const ::i32 * A, ::collection::count N)
825 return get_integer_mean(A, N);
829template <
typename TYPE, ::enum_type t_etypeContainer >
830TYPE numeric_array_base < TYPE, t_etypeContainer >::simple_total_mean()
833 return ::simple_total_mean(this->get_data(), this->get_count());
838template <
typename TYPE, ::enum_type t_etypeContainer >
839void numeric_array_base < TYPE, t_etypeContainer >::set(
const TYPE & t, ::collection::index iStart, ::collection::index iEnd)
842 iEnd = this->get_upper_bound();
843 for(::collection::index i = iStart; i <= iEnd; i++)
850template <
typename TYPE, ::enum_type t_etypeContainer >
851void numeric_array_base < TYPE, t_etypeContainer >::divide(TYPE div)
853 ::collection::index i;
854 for(i = 0; i < this->get_size(); i++)
856 this->element_at(i) = this->element_at(i) / div;
860template <
typename TYPE, ::enum_type t_etypeContainer >
861numeric_array_base < TYPE, t_etypeContainer > numeric_array_base < TYPE, t_etypeContainer >::operator - (
const numeric_array_base < TYPE, t_etypeContainer > & a)
const
864 numeric_array_base < TYPE, t_etypeContainer > aRet(*
this);
872template <
typename TYPE, ::enum_type t_etypeContainer >
873numeric_array_base < TYPE, t_etypeContainer > numeric_array_base < TYPE, t_etypeContainer >::operator + (
const numeric_array_base < TYPE, t_etypeContainer > & a)
const
876 numeric_array_base < TYPE, t_etypeContainer > aRet(*
this);
884template <
typename TYPE, ::enum_type t_etypeContainer >
885numeric_array_base < TYPE, t_etypeContainer > & numeric_array_base < TYPE, t_etypeContainer >::operator -= (
const numeric_array_base < TYPE, t_etypeContainer > & a)
888 this->erase_array(a);
894template <
typename TYPE, ::enum_type t_etypeContainer >
895numeric_array_base < TYPE, t_etypeContainer > & numeric_array_base < TYPE, t_etypeContainer >::operator += (
const numeric_array_base < TYPE, t_etypeContainer > & a)
906template <
typename TYPE, ::enum_type t_etypeContainer >
907inline void numeric_array_base < TYPE, t_etypeContainer > ::push_last()
910 this->add(this->last());
915template <
typename TYPE, ::enum_type t_etypeContainer >
916inline TYPE numeric_array_base < TYPE, t_etypeContainer > ::pop_max()
919 TYPE lastelement = this->last();
921 TYPE nowpop = this->pop();
923 this->last() = maximum(nowpop, lastelement);
931template <
typename TYPE, ::enum_type t_etypeContainer >
932inline TYPE numeric_array_base < TYPE, t_etypeContainer > ::pop_max_last_add_up(TYPE tLastAddUp)
935 TYPE lastelement = this->last();
937 TYPE nowpop = this->pop();
939 this->last() = maximum(nowpop, lastelement + tLastAddUp);
947template <
typename TYPE, ::enum_type t_etypeContainer >
948inline TYPE numeric_array_base < TYPE, t_etypeContainer > ::pop_to()
951 TYPE lastelement = this->pop();
953 this->last() = lastelement;
961template <
typename TYPE, ::enum_type t_etypeContainer >
962unique_number_sort_array < TYPE, t_etypeContainer >::
963unique_number_sort_array()
967template <
typename TYPE, ::enum_type t_etypeContainer >
968unique_number_sort_array < TYPE, t_etypeContainer >::
969unique_number_sort_array(
const unique_number_sort_array < TYPE, t_etypeContainer > & a)
971 numeric_array_base < TYPE, t_etypeContainer > ::operator = (a);
1029 namespace numeric_array_base
1032 template <
class ARRAY >
1033 typename ARRAY::BASE_TYPE big_average(
const ARRAY & a)
1035 ::collection::count c = a.get_count();
1038 typename ARRAY::BASE_TYPE f = 0.0;
1039 typename ARRAY::BASE_TYPE fCount = (
typename ARRAY::BASE_TYPE) c;
1040 for(::collection::index i = 0; i < c; i++)
1042 f += a.element_at(i) / fCount;
1052#include "numeric_array_range.h"
1063 template<
class ARRAY>
1064 bool binary_search(ARRAY & a,
typename ARRAY::BASE_ARG_TYPE t,::collection::index & iIndex,::collection::index(* fCompare) (
typename ARRAY::BASE_ARG_TYPE,
typename ARRAY::BASE_ARG_TYPE));
1066 template<
class ARRAY, prototype_array INDEX_ARRAY >
1067 bool binary_search(ARRAY & a,
typename ARRAY::BASE_ARG_TYPE t,::collection::index & iIndex, less_predicate_base < typename ARRAY::BASE_ARG_TYPE > * pcompare, INDEX_ARRAY & ia);
1069 template<
class ARRAY, prototype_array INDEX_ARRAY>
1070 ::collection::index sort_add(ARRAY & a,
typename ARRAY::BASE_ARG_TYPE t,::collection::index(* fCompare) (
typename ARRAY::BASE_ARG_TYPE,
typename ARRAY::BASE_ARG_TYPE),INDEX_ARRAY & ia)
1072 ::collection::index iIndex = 0;
1073 binary_search(a, t, iIndex, fCompare, ia);
1074 a.insert_at(iIndex, t);
1079 template<
class ARRAY,
class ARRAY2, prototype_array INDEX_ARRAY >
1080 ::collection::count sort_add_array(ARRAY & a,ARRAY2 & a2,::collection::index(* fCompare) (
typename ARRAY::BASE_ARG_TYPE,
typename ARRAY::BASE_ARG_TYPE),INDEX_ARRAY & ia)
1082 for(::collection::index i = 0; i < a2.get_count(); i++)
1084 sort_add(a,a2[i],fCompare,ia);
1086 return a2.get_count();
1090 template<
class ARRAY, prototype_array INDEX_ARRAY >
1091 ::collection::count sort_erase(ARRAY & a,
typename ARRAY::BASE_ARG_TYPE t,::collection::index(* fCompare) (
typename ARRAY::BASE_ARG_TYPE,
typename ARRAY::BASE_ARG_TYPE), INDEX_ARRAY & ia)
1093 ::collection::count ca = 0;
1094 ::collection::index iFind = 0;
1095 while(binary_search(a,t, iFind, fCompare, ia))
1098 ::collection::index iIndex = ia[iFind];
1100 for(::collection::index i = 0; i < ia.get_size(); i++)
1120 template <
typename TYPE, ::enum_type t_etypeContainer >
1121 numeric_array_each < ::numeric_array_base < TYPE, t_etypeContainer > > each(::numeric_array_base < TYPE, t_etypeContainer > & a) {
return a; }
1122 template <
typename TYPE, ::enum_type t_etypeContainer >
1123 numeric_array_each < ::numeric_array_base < TYPE, t_etypeContainer > > all(::numeric_array_base < TYPE, t_etypeContainer > & a) {
return a; }
1124 template <
typename TYPE, ::enum_type t_etypeContainer >
1125 numeric_array_each < ::numeric_array_base < TYPE, t_etypeContainer > > range(::numeric_array_base < TYPE, t_etypeContainer > & a) {
return a; }
1127 template <
typename TYPE, ::enum_type t_etypeContainer >
1128 numeric_array_range < ::numeric_array_base < TYPE, t_etypeContainer > > each(::numeric_array_base < TYPE, t_etypeContainer > & a,::collection::index iBeg,::collection::count iCount) {
return numeric_array_range < ::numeric_array_base < TYPE, t_etypeContainer > >(a,iBeg,iCount); }
1129 template <
typename TYPE, ::enum_type t_etypeContainer >
1130 numeric_array_range < ::numeric_array_base < TYPE, t_etypeContainer > > all(::numeric_array_base < TYPE, t_etypeContainer > & a,::collection::index iBeg,::collection::count iCount) {
return numeric_array_range < ::numeric_array_base < TYPE, t_etypeContainer > >(a,iBeg,iCount); }
1131 template <
typename TYPE, ::enum_type t_etypeContainer >
1132 numeric_array_range < ::numeric_array_base < TYPE, t_etypeContainer > > range(::numeric_array_base < TYPE, t_etypeContainer > & a,::collection::index iBeg,::collection::count iCount) {
return numeric_array_range < ::numeric_array_base < TYPE, t_etypeContainer > >(a,iBeg,iCount); }
1134 template <
typename TYPE, ::enum_type t_etypeContainer >
1135 void quick_sort(::numeric_array_base < TYPE, t_etypeContainer > & a,
bool bAsc =
true);
1137 template <
typename TYPE, ::enum_type t_etypeContainer >
1138 ::collection::count erase_greater_than(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE hi)
1141 ::collection::count ca = 0;
1143 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1145 if(a.element_at(i) > hi)
1157 template <
typename TYPE, ::enum_type t_etypeContainer >
1158 ::collection::count erase_greater_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE hi)
1161 ::collection::count ca = 0;
1163 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1165 if(a.element_at(i) >= hi)
1177 template <
typename TYPE, ::enum_type t_etypeContainer >
1178 ::collection::count erase_lesser_than(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE lo)
1181 ::collection::count ca = 0;
1183 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1185 if(a.element_at(i) < lo)
1197 template <
typename TYPE, ::enum_type t_etypeContainer >
1198 ::collection::count erase_lesser_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE lo)
1201 ::collection::count ca = 0;
1203 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1205 if(a.element_at(i) <= lo)
1217 template <
typename TYPE, ::enum_type t_etypeContainer >
1218 ::collection::count erase_lesser_than_or_greater_than(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE lo,TYPE hi)
1221 ::collection::count ca = 0;
1223 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1225 if(a.element_at(i) < lo)
1230 else if(a.element_at(i) > hi)
1242 template <
typename TYPE, ::enum_type t_etypeContainer >
1243 ::collection::count erase_lesser_than_or_greater_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE lo,TYPE hi)
1246 ::collection::count ca = 0;
1248 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1250 if(a.element_at(i) < lo)
1255 else if(a.element_at(i) >= hi)
1267 template <
typename TYPE, ::enum_type t_etypeContainer >
1268 ::collection::count erase_lesser_than_or_equal_or_greater_than(::numeric_array_base < TYPE, t_etypeContainer > & a,TYPE lo,TYPE hi)
1271 ::collection::count ca = 0;
1273 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1275 if(a.element_at(i) <= lo)
1280 else if(a.element_at(i) > hi)
1292 template <
typename TYPE, ::enum_type t_etypeContainer >
1293 ::collection::count erase_lesser_than_or_equal_or_greater_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer > & a, TYPE lo,TYPE hi)
1296 ::collection::count ca = 0;
1298 for(::collection::index i = a.get_upper_bound(); i >= 0; i--)
1300 if(a.element_at(i) <= lo)
1305 else if(a.element_at(i) >= hi)
1362 template <
typename ARRAY1,
typename ARRAY2 >
1363 inline bool is_equal(
const ARRAY1 & a1,
const ARRAY2 & a2)
1366 if (a1.get_count() != a2.get_count())
1373 for (::i32 i = 0; i < a1.get_count(); i++)
1390 template <
typename ARRAY_TYPE,
typename PRED >
1391 void predicate_sort(ARRAY_TYPE & a, PRED pred)
1394 index_array stackLowerBound;
1396 index_array stackUpperBound;
1402 iptr iLPos, iUPos, iMPos;
1404 if (a.get_size() >= 2)
1407 stackLowerBound.push(0);
1409 stackUpperBound.push(a.get_size() - 1);
1414 iLowerBound = stackLowerBound.pop();
1416 iUpperBound = stackUpperBound.pop();
1418 iLPos = iLowerBound;
1420 iMPos = iLowerBound;
1422 iUPos = iUpperBound;
1433 goto break_mid_loop;
1437 if (!pred(a[iUPos], a[iMPos]))
1446 a.__swap(iMPos, iUPos);
1462 goto break_mid_loop;
1466 if (!pred(a[iMPos], a[iLPos]))
1475 a.__swap(iLPos, iMPos);
1490 if (iLowerBound < iMPos - 1)
1493 stackLowerBound.push(iLowerBound);
1495 stackUpperBound.push(iMPos - 1);
1499 if (iMPos + 1 < iUpperBound)
1502 stackLowerBound.push(iMPos + 1);
1504 stackUpperBound.push(iUpperBound);
1508 if (stackLowerBound.count() == 0)
1521 template <
typename ARRAY_TYPE,
typename T,
typename PRED >
1522 iptr predicate_binary_search(
const ARRAY_TYPE & a,
const T & t, PRED pred)
1525 iptr iLPos, iUPos, iMPos;
1529 iUPos = a.get_upper_bound();
1531 while(iLPos <= iUPos)
1534 iMPos = (iLPos + iUPos) / 2;
1536 if (pred(a[iMPos], t))
1539 if (pred(t, a[iMPos]))
1556 if (!pred(t, a[iMPos]))
1586template <
typename TYPE,
typename ARG_TYPE,
typename TYPED,
typename MEMORY, ::enum_type t_etypeContainer >
1587template <
typename PRED >
1588void base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::predicate_sort(PRED pred)
1591 ::acme::array::predicate_sort(*
this, pred);
1596template <
typename TYPE,
typename ARG_TYPE,
typename TYPED,
typename MEMORY,::enum_type t_etypeContainer >
1597template <
typename T,
typename PRED >
1598::collection::index base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >::predicate_binary_search(
const T & t, PRED pred)
const
1601 return ::acme::array::predicate_binary_search(*
this, t, pred);
1606template < prototype_container CONTAINER1, prototype_container CONTAINER2 >
1607CONTAINER1 operator + (
const CONTAINER1 & container1,
const CONTAINER2 & container2)
1610 auto container = container1;
1612 container.append(container2);
1614 return ::transfer(container);
::collection::index erase_at(::collection::index nIndex, ::collection::count nCount=1)
Definition aaa__array_base_impl.h:62
Definition numeric_array.h:37
Definition numeric_info.h:672
include "aura/graphics/image/context.h"
Definition aaaa__defer.h:32