acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_array.h
1// Created by camilo on 2022-11-08 16:53 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include "integer_map.h"
6
7
8namespace acme
9{
10
11
12 namespace array
13 {
14
15
16 template<prototype_array ARRAY1, prototype_array ARRAY2>
17 bool is_equal(const ARRAY1 & array1, const ARRAY2 & array2)
18 {
19
20 if (array1.get_size() != array2.get_size())
21 {
22
23 return false;
24
25 }
26
27 for (::collection::index i = 0; i < array1.get_size(); i++)
28 {
29
30 if (array1.element_at(i) != array2.element_at(i))
31 {
32
33 return false;
34
35 }
36
37 }
38
39 return true;
40
41 }
42
43
44 template<prototype_array ARRAY1, prototype_array ARRAY2>
45 bool is_different(const ARRAY1 & array1, const ARRAY2 & array2)
46 {
47
48 return !is_equal(array1, array2);
49
50 }
51
52
53 } // namespace array
54
55
56} // namespace acme
57
58
59
60
61
62// From _papaya_array.h by camilo on 2022-10-22 18:18 <3ThomasBorregaardSorensen!!
63// From _papaya_array_impl.h by camilo on 2022-10-22 18:07 <3ThomasBorregaardSorensen!!
64#pragma once
65
66
67//#include "acme/prototype/collection/pointer_array_process.h"
68#include "acme/prototype/prototype/compare_predicate.h"
69//#include "acme/prototype/prototype/payload.h"
70//#include "acme/prototype/prototype/payload_array.h"
71
72
73template < class TYPE, class ARG_TYPE = const TYPE &, class TYPED = ::typed::nodef < TYPE >, class MEMORY = ::heap::typed_memory < TYPE, ::heap::e_memory_array >, ::enum_type t_etypeContainer = e_type_element >
74inline auto& __array_object(::base_array < TYPE, ARG_TYPE, TYPED, MEMORY, t_etypeContainer >& a, ::collection::index i);
75
76
77template < typename ARRAY_TYPE, typename T >
78inline auto& __array_object(::pointer_array_process < ARRAY_TYPE, T >& a, ::collection::index i);
79
80
81namespace acme
82{
83
84
85 template < class TDST, class TSRC >
86 ::collection::count copy(pointer_array < TDST >& dsta, const pointer_array < TSRC >& srca);
87
88
89 template < class A, class T >
90 A make_array(T t1)
91 {
92
93 A a;
94 a.add(t1);
95 return a;
96
97 }
98
99
100 namespace ptra
101 {
102
103
104 template < class TDST, class TSRC >
105 ::collection::count copy(address_array_base < TDST >& dsta, const address_array_base < TSRC >& srca);
106
107 template < class TDST, class TSRC >
108 ::collection::count ptrcopy(TDST& dsta, const TSRC& srca);
109
110
111 }
112
113
114 namespace array
115 {
116
117
118 template < class TDST, class TSRC >
119 ::collection::count copy(TDST& dsta, const TSRC& srca);
120
121 template < typename CONTAINER, class TYPE >
122 bool contains_item(const CONTAINER& container, const TYPE& t);
123
124
125 //#ifdef UNIVERSAL_WINDOWS
126 //
127 // template < typename T, typename ITEM >
128 // inline ::collection::index find_first_item(::winrt::Windows::Foundation::Collections::IVectorImpact < T > ^ ivectorview, const ITEM & item)
129 // {
130 //
131 // for (::u32 u = 0; u < ivectorview->Size; u++)
132 // {
133 //
134 // if (ivectorview->GetAt(u) == item)
135 // {
136 //
137 // return u;
138 //
139 // }
140 //
141 // }
142 //
143 // return -1;
144 //
145 // }
146 //
147 //
148 // template < typename T, typename ITEM >
149 // inline bool contains_item(::winrt::Windows::Foundation::Collections::IVectorImpact < T > ^ ivectorview, const ITEM & item)
150 // {
151 //
152 // auto iFindFirst = find_first_item(ivectorview, item);
153 //
154 // return iFindFirst >= 0;
155 //
156 // }
157 //
158 //
159 //#endif
160
161
162 template < class TINTERSECTION, class TDST, class TSRC >
163 void intersection(TINTERSECTION& intersection, const TDST& dsta, const TSRC& srca);
164
165 template < class A >
166 void randomize(A& a)
167 {
168
169 A b;
170
171 while (a.get_count() > 0)
172 {
173
174 ::collection::index i = (::collection::index)(rand() % a.get_size());
175 b.add(a.element_at(i));
176 a.erase_at(i);
177
178 }
179
180 a = b;
181
182 }
183
184
185 template < class A >
186 typename A::BASE_TYPE pick_random(A& a)
187 {
188
189 ::collection::index i = (::collection::index)(rand() % a.get_size());
190
191 return a.element_at(i);
192
193 }
194
195
196 template < class A >
197 typename A::BASE_TYPE pop_random(A& a)
198 {
199
200 ::collection::index i = (::collection::index)(rand() % a.get_size());
201
202 auto matter = a.element_at(i);
203
204 a.erase_at(i);
205
206 return matter;
207
208 }
209
210
211 template < class A, class TYPE >
212 ::collection::count populate(A& a, TYPE start, TYPE end, TYPE step, bool bIncludeStart = true, bool bIncludeEnd = true, bool bIncludeEndOnStep = true)
213 {
214
215 ::collection::count count = 0;
216
217 TYPE cur = start;
218
219 if (bIncludeStart)
220 {
221
222 if (start == end)
223 {
224
225 if (bIncludeEnd)
226 {
227
228 a.add(cur);
229
230 return 1;
231
232 }
233 else
234 {
235
236 return 0;
237
238 }
239
240 }
241 else
242 {
243
244 a.add(cur);
245
246 count++;
247
248 }
249
250 }
251
252 if (end > start)
253 {
254
255 if (step == 0)
256 {
257
258 return count;
259
260 }
261
262 if (step < 0)
263 {
264
265 step = -step;
266
267 }
268
269 while (true)
270 {
271
272 cur = cur + step;
273
274 if (cur >= end)
275 {
276
277 break;
278
279 }
280
281 a.add(cur);
282
283 count++;
284
285 }
286
287 }
288 else
289 {
290
291 if (step == 0)
292 {
293
294 return count;
295
296 }
297
298 if (step < 0)
299 {
300
301 step = -step;
302
303 }
304
305 while (true)
306 {
307
308 cur = cur - step;
309
310 if (cur <= end)
311 {
312
313 break;
314
315 }
316
317 a.add(cur);
318
319 count++;
320
321 }
322
323 }
324
325 if (bIncludeEnd)
326 {
327
328 if (bIncludeEndOnStep)
329 {
330
331 if (cur == end)
332 {
333
334 a.add(cur);
335
336 return count + 1;
337
338 }
339 else
340 {
341
342 return count;
343
344 }
345
346 }
347 else
348 {
349
350 a.add(cur);
351
352 return count + 1;
353
354 }
355
356 }
357 else
358 {
359
360 return count;
361
362 }
363
364 }
365
366
367 template < typename ARRAY >
368 ::collection::index find_first(const ARRAY& a, typename ARRAY::BASE_ARG_TYPE t, ::collection::index(*pfnCompare)(typename ARRAY::BASE_ARG_TYPE, typename ARRAY::BASE_ARG_TYPE), ::collection::index find = 0, ::collection::index last = -1)
369 {
370
371 if (find < 0)
372 {
373
374 find += a.get_count();
375
376 }
377
378 if (last < 0)
379 {
380
381 last += a.get_count();
382
383 }
384
385 for (; find <= last; find++)
386 {
387
388 if (pfnCompare((typename ARRAY::BASE_ARG_TYPE)a.element_at(find), (typename ARRAY::BASE_ARG_TYPE)t) == 0)
389 {
390
391 return find;
392
393 }
394
395 }
396
397 return -1;
398
399 }
400
401
402
403
404
405 namespace every
406 {
407
408 template < typename A >
409 bool ci_is(const A& a, const typename A::BASE_TYPE& t)
410 {
411
412 for (auto& i : a)
413 {
414
415 if (::case_insensitive_ansi_compare(i, t))
416 {
417
418 return false;
419
420 }
421
422 }
423
424 return true;
425
426 }
427
428 template < typename A >
429 bool is_true(A&& a)
430 {
431
432 for (auto& i : a)
433 {
434
435 if ((bool)i)
436 {
437
438 return true;
439
440 }
441
442 }
443
444 return false;
445
446 }
447
448
449 }
450
451
452 } // namespace array
453
454
455
456 template < class A >
457 void array_merge(A& a, const A& a1, const A& a2)
458 {
459 a = a1 + a2;
460 }
461
462 template < class A >
463 void array_makecombination(pointer_array < A >& comb, const A& a, A blindprefixa = A(), ::collection::index idx = 0)
464 {
465 comb.add(allocateø A(blindprefixa));
466 for (::collection::index i = idx; i < a.get_count(); i++)
467 {
468 array_makecombination(comb, a, blindprefixa + make_array < A >(a[i]), i + 1);
469 }
470 }
471
472 /*
473 function array_arrange($a)
474 {
475 $comb = array_makecombination($a);
476 $ret = array();
477 $count = count($comb);
478 foreach($comb as $ai)
479 {
480 if(count($ai) > 0)
481 $ret = array_merge($ret, array_permute($ai));
482 }
483 return $ret;
484 }*/
485
486 template < class A, class A2D >
487 void array_permute(A2D& perm, const A& a);
488
489 template < class A >
490 void array_permute(pointer_array < A >& perm, const A& a);
491
492 CLASS_DECL_ACME string_array_base x1_decode_ida(const ::scoped_string & scopedstr);
493
494 CLASS_DECL_ACME string x1_encode_ida(const string_array_base& stra);
495
496
497 template < class A >
498 void x1_on_erase(const A& a, typename A::BASE_TYPE& n)
499 {
500 ::collection::count c = 0;
501 for (::collection::index i = 0; i < a.get_size(); i++)
502 {
503 if (a[i] < n)
504 {
505 c++;
506 }
507 }
508 n -= c;
509 }
510
511
512 namespace array
513 {
514
515
516 //template < typename TYPE >
517 //::stream & write_container_as_parent(::stream & stream, const pointer_array < TYPE > & a);
518
519 //template < typename TYPE >
520 //::stream & read_container_as_parent(::stream & stream, pointer_array < TYPE > & a);
521
522 //template < typename TYPE, typename INITIALIZER >
523 //::stream & exchange_container(::stream & stream, INITIALIZER * pinitializer, const pointer_array < TYPE > & a);
524
525 template < typename Type, typename RawType, ::enum_type t_etypeContainer >
526 ::collection::index add(string_base_array < Type, RawType, t_etypeContainer >& array, const Type& psz)
527 {
528
529 auto iIndex = __index(array.m_nSize);
530
531 array.set_at_grow(iIndex, psz);
532
533 return iIndex;
534
535 }
536
537
538 template < typename Type, typename RawType, ::enum_type t_etypeContainer >
539 ::collection::index add(string_base_array < Type, RawType, t_etypeContainer >& array, const ::payload& payload);
540
541
542 template < typename Type, typename RawType, ::enum_type t_etypeContainer >
543 ::collection::index unfold_add(string_base_array < Type, RawType, t_etypeContainer >& array, const ::payload& payload);
544
545 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
546 ::collection::count ensure_sequence(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE start, TYPE end, TYPE increment = 1);
547
548 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
549 ::collection::count append_sequence(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE iterator, TYPE end, TYPE increment = 1);
550
551 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
552 ::collection::count set_sequence(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE start, TYPE end, TYPE increment = 1);
553
554 template<class ARRAY>
555 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));
556
557 template<class ARRAY>
558 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);
559
560 template<class ARRAY>
561 ::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);
562
563 template<class ARRAY, class ARRAY2>
564 ::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);
565
566 template<class ARRAY>
567 inline typename ARRAY::BASE_TYPE pop(ARRAY& a, ::collection::index n = -1);
568
569 template<class ARRAY>
570 inline void pop_back(ARRAY& a, ::collection::index n = -1);
571
572 template<class ARRAY>
573 inline ::collection::index push(ARRAY& a, typename ARRAY::BASE_ARG_TYPE newElement, ::collection::index n = 0);
574
575 template<class ARRAY>
576 inline void add(ARRAY& a, typename ARRAY::BASE_ARG_TYPE newElement, ::collection::index n = 0);
577
578 template<class TARGET, class SOURCE> inline ::collection::index add(TARGET& target, const SOURCE& source)
579 {
580
581 return target.add(source);
582
583 }
584
585
586 template < typename ARRAY1, typename ARRAY2>
587 inline ::collection::index add_array(ARRAY1& array1, const ARRAY2& array2)
588 {
589
590 ::collection::index i = -1;
591
592 for (auto& item : array2)
593 {
594
595 ::collection::index iItem = array1.add_item(item);
596
597 if (i < 0)
598 {
599
600 i = iItem;
601
602 }
603
604 }
605
606 return i;
607
608 }
609
610
611 template < typename ARRAY1, typename ARRAY2>
612 inline ::collection::index unfold_array(ARRAY1& array1, const ARRAY2& array2)
613 {
614
615 ::collection::index i = -1;
616
617 for (auto& item : array2)
618 {
619
620 ::collection::index iItem = add(array1, item);
621
622 if (i < 0)
623 {
624
625 i = iItem;
626
627 }
628
629 }
630
631 return i;
632
633 }
634
635
636 inline ::collection::index add(string_array_base& stra, const ::scoped_string & scopedstr);
637 inline ::collection::index add(string_array_base& stra, const ::i8& ch);
638 inline ::collection::index add(string_array_base& stra, const ansi_string& str);
639 inline ::collection::index add(string_array_base& stra, const wide_string& str);
640 inline ::collection::index add(string_array_base& stra, const ::file::path& path);
641 inline ::collection::index add(string_array_base& stra, const ::payload& payload);
642 inline ::collection::index add(string_array_base& stra, const ::property& property);
643 inline ::collection::index add(string_array_base& stra, const ::property_set& propertyset);
644
645 inline ::collection::index add(::file::path_array_base& patha, const ::scoped_string & scopedstr);
646
647 inline ::collection::index add(string_array_base& stra, const string_array_base& straSource);
648
649 inline ::collection::index add(::file::path_array_base& patha, const string_array_base& stra);
650 inline ::collection::index add(::file::path_array_base& patha, const ::file::path_array_base& pathaSrc);
651 inline ::collection::index add(::file::path_array_base& patha, const ::file::listing_base& listing);
652
653 template < typename T >
654 inline bool are_all_elements_equal(const pointer_array < T >& a1, const pointer_array < T >& a2);
655
656 // t1 candidate bigger
657 template < typename T1, typename T2>
658 inline bool contains_array(const T1& t1, const T2& t2);
659
660
661 template < typename T1, typename T2>
662 inline ::collection::count erase_array(T1& t1, T2&& t2);
663
664
665 template < typename T1, typename T2>
666 inline bool equals_non_unique_unordered(const T1& t1, const T2& t2)
667 {
668
669 return ::acme::array::contains_array(t1, t2) && ::acme::array::contains_array(t2, t1);
670
671 }
672
673 template < typename A, typename PTRA >
674 void ptra(PTRA& ptra, const A& a)
675 {
676
677 for (auto& item : a)
678 {
679
680 ptra.add((typename PTRA::BASE_TYPE) item);
681
682 }
683
684 }
685
686
687 template < typename A >
688 ::array < const_char_pointer >psza(const A& a)
689 {
690
691 ::array < const_char_pointer >pa;
692
693 ptra(pa, a);
694
695 pa.add(nullptr);
696
697 return pa;
698
699 }
700
701
702 template < typename A, typename PA >
703 void copy_points(A& a, const PA* pa, ::collection::count c);
704
705
706 } // namespace array
707
708 namespace array2d
709 {
710
711 template < typename A >
712 ::collection::count predominant_column_count(A& a);
713
714 } // namespace array2d
715
716
717 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
718 ::collection::count erase_greater_than(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE hi);
719
720
721 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
722 ::collection::count erase_greater_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE hi);
723
724
725 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
726 ::collection::count erase_lesser_than(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE lo);
727
728
729 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
730 ::collection::count erase_lesser_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE lo);
731
732
733 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
734 ::collection::count erase_lesser_than_or_greater_than(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE lo, TYPE hi);
735
736
737 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
738 ::collection::count erase_lesser_than_or_greater_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE lo, TYPE hi);
739
740
741 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
742 ::collection::count erase_lesser_than_or_equal_or_greater_than(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE lo, TYPE hi);
743
744
745 template < typename TYPE, ::enum_type t_etypeContainer = e_type_element >
746 ::collection::count erase_lesser_than_or_equal_or_greater_than_or_equal(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE lo, TYPE hi);
747
748
749} // namespace acme
750
751
752
753
754
755
756namespace acme
757{
758
759
760 namespace array
761 {
762
763
764 //template < typename ARRAY >
765 //inline void load(ARRAY & a, stream & s)
766 //{
767
768 // ::collection::count cSerialized = 0;
769
770 // ::collection::count c = 0;
771
772 // s >> c;
773
774 // //if (!s.fail())
775 // /*{
776
777 // try
778 // {*/
779
780 // for (::collection::index i = 0; i < c; i++)
781 // {
782
783 // a.set_size(i + 1, minimum((size_t)(c - i), 96_mb / sizeof(a[0])));
784
785 // auto & item = __typed(a[i]);
786
787 // s >> item;
788
789 // cSerialized++;
790
791 // //if (s.fail())
792 // //{
793
794 // // break;
795
796 // //}
797
798 // }
799
800 // //}
801 // //catch (...)
802 // //{
803
804 // // //s.set_fail_bit();
805
806 // //}
807
808 // //if (s.fail())
809 // {
810
811 // a.set_size(cSerialized);
812
813 // }
814
815 // //}
816
817 //}
818
819
820 //template < typename TYPE >
821 //::stream & exchange_container_as_parent(::stream & stream, const pointer_array < TYPE > & a)
822 //{
823
824 // ::collection::count c = a.get_count();
825
826 // stream.exchange(::atom(), c);
827
828 // //if (stream.fail())
829 // //{
830
831 // // return stream;
832
833 // //}
834
835 // for (::collection::index i = 0; i < c; i++)
836 // {
837
838 // auto & pitem = ((pointer_array < TYPE > &) a).element_at_grow(i);
839
840 // if (!pitem)
841 // {
842
843 // pitem = allocateø TYPE(&(pointer_array < TYPE > &)a);
844
845 // }
846
847 // pitem->exchange(stream);
848
849 // //if (stream.fail())
850 // //{
851
852 // // break;
853
854 // //}
855
856 // }
857
858 // return stream;
859
860 //}
861
862
863 //template < typename TYPE, typename INITIALIZER >
864 //::stream & exchange_container(::stream & stream, INITIALIZER * pinitializer, const pointer_array < TYPE > & a)
865 //{
866
867 // ::collection::count c = a.get_count();
868
869 // stream.exchange(::atom(), c);
870
871 // //if (stream.fail())
872 // //{
873
874 // // return stream;
875
876 // //}
877
878 // for (::collection::index i = 0; i < c; i++)
879 // {
880
881 // auto & pitem = ((pointer_array < TYPE > &) a).element_at_grow(i);
882
883 // if (!pitem)
884 // {
885
886 // pinitializer->__initialize(pitem);
887
888 // //pitem = allocateø TYPE(&(pointer_array < TYPE > &)a);
889
890 // }
891
892 // pitem->exchange(stream);
893
894 // //if (stream.fail())
895 // //{
896
897 // // break;
898
899 // //}
900
901 // }
902
903 // return stream;
904
905 //}
906
907
908 //template < typename TYPE >
909 //::stream & write_container_as_parent(::stream & stream, const pointer_array < TYPE > & a)
910 //{
911
912 // ::collection::count c = a.get_count();
913
914 // stream << c;
915
916 // //if (stream.fail())
917 // //{
918
919 // // return stream;
920
921 // //}
922
923 // for (auto & item : a)
924 // {
925
926 // stream << item;
927
928 // c--;
929
930 // }
931
932 // return stream;
933
934 //}
935
936
937 template < typename Type, typename RawType, ::enum_type t_etypeContainer >
938 ::collection::index add(string_base_array < Type, RawType, t_etypeContainer >& array, const ::payload& payload)
939 {
940
941 ::collection::index i = -1;
942
943 if (payload.is_empty())
944 {
945
946 }
947 else if (payload.get_type() == ::e_type_string_array)
948 {
949
950 i = ::acme::array::add(array, payload.as_string_array());
951
952 }
953 else if (payload.cast < string_base_array < Type, RawType, t_etypeContainer > >() != nullptr)
954 {
955
956 i = ::acme::array::add(array, *payload.cast < string_base_array < Type, RawType, t_etypeContainer > >());
957
958 }
959 else if (payload.get_type() == ::e_type_payload_array)
960 {
961
962 for (::collection::index i = 0; i < payload.as_payload_array().get_count(); i++)
963 {
964
965 ::collection::index iItem = ::acme::array::add(array, payload.as_payload_array()[i]);
966
967 if (i < 0)
968 {
969
970 i = iItem;
971
972 }
973
974 }
975
976 }
977 else if (payload.get_type() == ::e_type_int_array)
978 {
979
980 array.copy(payload.as_int_array());
981
982 }
983 else if (payload.get_type() == ::e_type_property_set)
984 {
985
986 auto & set = payload.property_set_reference();
987
988 for (auto& property : set)
989 {
990
991 auto iItem = ::acme::array::add(array, property);
992
993 if (i < 0)
994 {
995
996 i = iItem;
997
998 }
999
1000 }
1001
1002 }
1003 else
1004 {
1005
1006 i = ::acme::array::add(array, payload);
1007
1008 }
1009
1010 return i;
1011
1012 }
1013
1014
1015 //template < typename TYPE >
1016 //::stream & read_container_as_parent(::stream & stream, pointer_array < TYPE > & a)
1017 //{
1018
1019 // ::collection::count c = 0;
1020
1021 // stream >> c;
1022
1023 // //if (stream.fail())
1024 // //{
1025
1026 // // return stream;
1027
1028 // //}
1029
1030 // while (c > 0)
1031 // {
1032
1033 // auto p = allocateø TYPE(&a);
1034
1035 // stream >> *p;
1036
1037 // /* if (stream.fail())
1038 // {
1039
1040 // break;
1041
1042 // }*/
1043
1044 // a.add(p);
1045
1046 // c--;
1047
1048 // }
1049
1050 // return stream;
1051
1052 //}
1053
1054
1055 template < class TDST, class TSRC >
1056 ::collection::count copy(TDST& dsta, const TSRC& srca)
1057 {
1058
1059 dsta.erase_all();
1060
1061 for (::i32 i = 0; i < srca.get_size(); i++)
1062 {
1063
1064 dsta.add((typename TDST::BASE_TYPE) srca[i]);
1065
1066 }
1067
1068 return dsta.get_count();
1069
1070 }
1071
1072
1073 //template < class TDST, class TSRC >
1074 //::collection::count copy(TDST & dsta, const TSRC & srca);
1075
1076
1077 template < typename CONTAINER, class TYPE >
1078 bool contains_item(const CONTAINER& container, const TYPE& t)
1079 {
1080
1081 for (auto& item : container)
1082 {
1083
1084 if (item == t)
1085 {
1086
1087 return true;
1088
1089 }
1090
1091 }
1092
1093 return false;
1094
1095 }
1096
1097
1098 // t1 candidate bigger
1099 template < typename T1, typename T2>
1100 inline bool contains_array(const T1& t1, const T2& t2)
1101 {
1102
1103 for (auto& t : t2)
1104 {
1105
1106 if (!contains_item(t1, t))
1107 {
1108
1109 return false;
1110
1111 }
1112
1113 }
1114
1115 return true;
1116
1117 }
1118
1119
1120
1121
1122 template < class TINTERSECTION, class TDST, class TSRC >
1123 void intersection(TINTERSECTION& intersection, const TDST& dsta, const TSRC& srca)
1124 {
1125
1126 intersection.clear();
1127
1128 for (auto& item : dsta)
1129 {
1130
1131 if (contains_item(srca, item))
1132 {
1133
1134 intersection.add(item);
1135
1136 }
1137
1138 }
1139
1140 }
1141
1142 template < typename T1, typename T2>
1143 inline ::collection::count erase_array(T1& t1, T2&& t2)
1144 {
1145
1146 ::collection::count c = 0;
1147
1148 for (auto& t : t2)
1149 {
1150
1151 c += t1.erase(t);
1152
1153 }
1154
1155 return c;
1156
1157 }
1158
1159
1160
1161
1162 //template < class TDST, class TSRC >
1163 //::collection::count copy(TDST & dsta, const TSRC & srca)
1164 //{
1165
1166 // ::collection::count c = srca.get_count();
1167
1168 // dsta.set_size(c);
1169
1170 // for (::i32 i = 0; i < c; i++)
1171 // {
1172
1173 // dsta[i] = (typename TDST::BASE_TYPE) srca[i];
1174
1175 // }
1176
1177 // return c;
1178
1179 //}
1180
1181 //template < class ARRAY >
1182 //::collection::count copy_same_class(ARRAY & dsta, const ARRAY & srca)
1183 //{
1184
1185 // ::collection::count c = srca.get_count();
1186
1187 // dsta.set_size(c);
1188
1189 // for (::i32 i = 0; i < c; i++)
1190 // {
1191
1192 // dsta[i] = srca[i];
1193
1194 // }
1195
1196 // return c;
1197
1198 //}
1199
1200
1201 template < typename A, typename PA >
1202 void copy_points(A& a, const PA* pa, ::collection::count c)
1203 {
1204
1205 a.set_size(c);
1206
1207 for (::collection::index i = 0; i < c; i++)
1208 {
1209
1210 a[i] = (typename A::BASE_TYPE) pa[i];
1211
1212 }
1213
1214 }
1215
1216 } // namespace array
1217
1218
1219 template < class TDST, class TSRC >
1220 ::collection::count copy(pointer_array < TDST >& dsta, const pointer_array < TSRC >& srca)
1221 {
1222
1223 ::collection::count ca = 0;
1224
1225 dsta.erase_all();
1226
1227 for (::i32 i = 0; i < srca.get_size(); i++)
1228 {
1229 dsta.add(allocateø TSRC(srca(i)));
1230 ca++;
1231 }
1232
1233 return ca;
1234
1235 }
1236
1237 namespace ptra
1238 {
1239
1240 template < class TDST, class TSRC >
1241 ::collection::count copy(address_array_base < TDST >& dsta, const address_array_base < TSRC >& srca)
1242 {
1243
1244 ::collection::count ca = 0;
1245
1246 dsta.erase_all();
1247
1248 for (::i32 i = 0; i < srca.get_size(); i++)
1249 {
1250 dsta.add(___new TSRC (srca(i)));
1251 ca++;
1252 }
1253
1254 return ca;
1255
1256 }
1257
1258 template < class TDST, class TSRC >
1259 ::collection::count ptrcopy(TDST& dsta, const TSRC& srca)
1260 {
1261
1262 ::collection::count ca = 0;
1263
1264 dsta.erase_all();
1265
1266 for (::i32 i = 0; i < srca.get_size(); i++)
1267 {
1268 dsta.add(srca[i]);
1269 ca++;
1270 }
1271
1272 return ca;
1273
1274 }
1275
1276 }
1277
1278
1279 template < class A, class A2D >
1280 void array_permute(A2D& perm, const A& a)
1281 {
1282 ::collection::count count = a.get_count();
1283 if (count == 1)
1284 {
1285 perm.add(a);
1286 return;
1287 }
1288 A elema;
1289 A topermut;
1290 A2D perm2;
1291 for (::i32 i = 0; i < count; i++)
1292 {
1293 elema.erase_all();
1294 elema.add(a[i]);
1295 topermut.erase_all();
1296 for (::i32 j = 0; j < i; j++)
1297 {
1298 topermut.add(a[j]);
1299 }
1300 for (::i32 j = i + 1; j < count; j++)
1301 {
1302 topermut.add(a[j]);
1303 }
1304 perm2.erase_all();
1305 array_permute(perm2, topermut);
1306 for (::i32 j = 0; j < perm2.get_count(); j++)
1307 {
1308 perm.add(elema + perm2[j]);
1309 }
1310 }
1311 }
1312
1313 template < class A >
1314 void array_permute(pointer_array < A >& perm, const A& a)
1315 {
1316 ::collection::count count = a.get_count();
1317 if (count == 1)
1318 {
1319 perm.add(allocateø A(a));
1320 return;
1321 }
1322 A elema;
1323 A topermut;
1324 pointer_array < A > perm2;
1325 for (::i32 i = 0; i < count; i++)
1326 {
1327 elema.erase_all();
1328 elema.add(a[i]);
1329 topermut.erase_all();
1330 for (::i32 j = 0; j < i; j++)
1331 {
1332 topermut.add(a[j]);
1333 }
1334 for (::i32 j = i + 1; j < count; j++)
1335 {
1336 topermut.add(a[j]);
1337 }
1338 perm2.erase_all();
1339 array_permute(perm2, topermut);
1340 for (::i32 j = 0; j < perm2.get_count(); j++)
1341 {
1342 perm.add(allocateø A(elema + perm2[j]));
1343 }
1344 }
1345 }
1346
1347} // namespace array
1348
1349
1350
1351
1352
1353
1354namespace acme
1355{
1356
1357
1358 namespace array
1359 {
1360
1361
1362
1367
1374
1375
1382
1383
1384 //inline ::collection::index add(string_array_base & stra, const ::payload & payload)
1385 //{
1386
1387 // ::collection::index iInsert = -1;
1388
1389 // if (payload.is_array())
1390 // {
1391
1392 // ::collection::count c = payload.array_get_count();
1393
1394 // for (::collection::index i = 0; i < c; i++)
1395 // {
1396
1397 // auto iItem = stra.add_item(payload.at(i));
1398
1399 // if (iInsert < 0)
1400 // {
1401
1402 // iInsert = iItem;
1403
1404 // }
1405
1406 // }
1407
1408 // }
1409 // else
1410 // {
1411
1412 // iInsert = stra.add_item(payload);
1413
1414 // }
1415
1416 // return iInsert;
1417
1418 //}
1419
1420 //inline ::collection::index add(string_array_base & stra, const ::property & property)
1421 //{
1422
1423 // return add(stra, (const ::payload &)property);
1424
1425 //}
1426
1427 //inline ::collection::index add(string_array_base & stra, const ::property_set & propertyset)
1428 //{
1429
1430 // ::collection::index iInsert = -1;
1431
1432 // ::collection::count c = propertyset.get_count();
1433
1434 // for (::collection::index i = 0; i < c; i++)
1435 // {
1436
1437 // auto iItem = stra.add_item(*propertyset.element_at(i));
1438
1439 // if (iInsert < 0)
1440 // {
1441
1442 // iInsert = iItem;
1443
1444 // }
1445
1446 // }
1447
1448 // return iInsert;
1449
1450 //}
1451
1452
1453
1455 //
1456 // Appending ARRAY
1457 // to array
1458
1459 //inline ::collection::index add(string_array_base & stra, const string_array_base & straSource) { return add_array(stra, straSource); }
1460
1461 //inline ::collection::index add(::file::path_array_base & patha, const string_array_base & stra) { return add_array(patha, stra); }
1462 //inline ::collection::index add(::file::path_array_base & patha, const ::file::path_array_base & pathaSrc) { return add_array(patha, pathaSrc); }
1463 //inline ::collection::index add(::file::path_array_base & patha, const ::file::listing_base & listing) { return add_array(patha, listing); }
1464
1465
1466 //template < typename TYPE, ::enum_type t_etypeContainer >
1467 //::collection::count ensure_sequence(::numeric_array_base < TYPE, t_etypeContainer > & aParam, TYPE start, TYPE end, TYPE increment)
1468 //{
1469
1470 // ::collection::count c = 0;
1471
1472 // ::numeric_array_base < TYPE, t_etypeContainer > a;
1473
1474 // ::acme::array::set_sequence(a, start, end, increment);
1475
1476 // c += erase_lesser_than_or_greater_than(aParam, start, end);
1477
1478 // for (::collection::index i = aParam.get_upper_bound(); i >= 0; i--)
1479 // {
1480
1481 // auto pFind = 0;
1482
1483 // if (::acme::array::binary_search(a, aParam.element_at(i), iFind, &::numeric_compare < typename ::numeric_array_base < TYPE, t_etypeContainer >::BASE_ARG_TYPE >))
1484 // {
1485
1486 // a.erase_at(iFind);
1487
1488 // c++;
1489
1490 // }
1491 // else
1492 // {
1493
1494 // aParam.erase_at(i);
1495
1496 // c++;
1497
1498 // }
1499
1500 // }
1501
1502 // c += aParam.add(a);
1503
1504 // return c;
1505
1506 //}
1507
1508
1509 template<class ARRAY>
1510 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))
1511 {
1512
1513 if (a.get_size() == 0)
1514 {
1515 return false;
1516 }
1517
1518 ::collection::index iLowerBound = 0;
1519 ::collection::index iMaxBound = a.get_upper_bound();
1520 ::collection::index iUpperBound = iMaxBound;
1521 ::collection::index iCompare;
1522 // do binary search
1523 iIndex = (iUpperBound + iLowerBound) / 2;
1524 while (iUpperBound - iLowerBound >= 8)
1525 {
1526 iCompare = fCompare(a.element_at(iIndex), t);
1527 if (iCompare == 0)
1528 {
1529 return true;
1530 }
1531 else if (iCompare > 0)
1532 {
1533 iUpperBound = iIndex - 1;
1534 if (iUpperBound < 0)
1535 {
1536 iIndex = 0;
1537 break;
1538 }
1539 }
1540 else
1541 {
1542 iLowerBound = iIndex + 1;
1543 if (iLowerBound > iMaxBound)
1544 {
1545 iIndex = iMaxBound + 1;
1546 break;
1547 }
1548 }
1549 iIndex = (iUpperBound + iLowerBound) / 2;
1550 }
1551 // do sequential search
1552 while (iIndex < a.get_count())
1553 {
1554 iCompare = fCompare(a.element_at(iIndex), t);
1555 if (iCompare == 0)
1556 return true;
1557 else if (iCompare < 0)
1558 iIndex++;
1559 else
1560 break;
1561 }
1562 if (iIndex >= a.get_count())
1563 return false;
1564 while (iIndex >= 0)
1565 {
1566 iCompare = fCompare(a.element_at(iIndex), t);
1567 if (iCompare == 0)
1568 return true;
1569 else if (iCompare > 0)
1570 iIndex--;
1571 else
1572 break;
1573 }
1574 iIndex++;
1575 return false;
1576
1577 }
1578
1579
1580 template<class ARRAY>
1581 bool binary_search(ARRAY& a, typename ARRAY::BASE_ARG_TYPE t, ::collection::index& iIndex, less_predicate_base < typename ARRAY::BASE_ARG_TYPE >* pless, index_array& ia)
1582 {
1583
1584 if (a.get_size() == 0)
1585 {
1586
1587 return false;
1588
1589 }
1590
1591 ::collection::index iLowerBound = 0;
1592 ::collection::index iMaxBound = a.get_upper_bound();
1593 ::collection::index iUpperBound = iMaxBound;
1594 ::collection::index iCompare;
1595
1596 // do binary search
1597 iIndex = (iUpperBound + iLowerBound) / 2;
1598
1599 while (iUpperBound - iLowerBound >= 8)
1600 {
1601
1602 iCompare = pless->less(a.element_at(iIndex), t);
1603
1604 if (iCompare == 0)
1605 {
1606
1607 return true;
1608
1609 }
1610 else if (iCompare > 0)
1611 {
1612
1613 iUpperBound = iIndex - 1;
1614
1615 if (iUpperBound < 0)
1616 {
1617
1618 iIndex = 0;
1619
1620 break;
1621
1622 }
1623
1624 }
1625 else
1626 {
1627
1628 iLowerBound = iIndex + 1;
1629
1630 if (iLowerBound > iMaxBound)
1631 {
1632
1633 iIndex = iMaxBound + 1;
1634
1635 break;
1636
1637 }
1638
1639 }
1640
1641 iIndex = (iUpperBound + iLowerBound) / 2;
1642
1643 }
1644
1645 // do sequential search
1646 while (iIndex < a.get_count())
1647 {
1648
1649 iCompare = pless->less(a.element_at(iIndex), t);
1650
1651 if (iCompare == 0)
1652 {
1653
1654 return true;
1655
1656 }
1657
1658 else if (iCompare < 0)
1659 {
1660
1661 iIndex++;
1662
1663 }
1664 else
1665 {
1666
1667 break;
1668
1669 }
1670
1671 }
1672
1673 if (iIndex >= a.get_count())
1674 {
1675
1676 return false;
1677
1678 }
1679
1680 while (iIndex >= 0)
1681 {
1682
1683 iCompare = pless->less(a.element_at(iIndex), t);
1684
1685 if (iCompare == 0)
1686 {
1687
1688 return true;
1689
1690 }
1691
1692 else if (iCompare > 0)
1693 {
1694
1695 iIndex--;
1696
1697 }
1698 else
1699 {
1700
1701 break;
1702
1703 }
1704
1705 }
1706
1707 iIndex++;
1708
1709 return false;
1710
1711 }
1712
1713
1714 template < typename TYPE, ::enum_type t_etypeContainer >
1715 ::collection::count append_sequence(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE iterator, TYPE end, TYPE increment)
1716 {
1717 if (increment == 0)
1718 {
1719 a.add(iterator);
1720 a.add(end);
1721 return 2;
1722 }
1723 else if (increment > 0)
1724 {
1725 ::collection::count ca = 0;
1726 for (; iterator <= end; iterator += increment)
1727 {
1728 a.add(iterator);
1729 ca++;
1730 }
1731 return ca;
1732 }
1733 else
1734 {
1735 ::collection::count ca = 0;
1736 for (; iterator >= end; iterator += increment)
1737 {
1738 a.add(iterator);
1739 ca++;
1740 }
1741 return ca;
1742 }
1743 }
1744
1745
1746 template < typename TYPE, ::enum_type t_etypeContainer >
1747 ::collection::count set_sequence(::numeric_array_base < TYPE, t_etypeContainer >& a, TYPE start, TYPE end, TYPE increment)
1748 {
1749 a.erase_all();
1750 return append_sequence(a, start, end, increment);
1751 }
1752
1753
1754 template < typename ARRAY >
1755 inline typename ARRAY::BASE_TYPE pop(ARRAY& a, ::collection::index n)
1756 {
1757
1758 ::collection::index i = a.get_upper_bound(n);
1759
1760 typename ARRAY::TYPE t = a.element_at(i);
1761
1762 a.erase_at(i);
1763
1764 return t;
1765
1766 }
1767
1768
1769 template < typename ARRAY >
1770 inline void pop_back(ARRAY& a, ::collection::index n)
1771 {
1772
1773 a.erase_at(a.get_upper_bound(n));
1774
1775 }
1776
1777
1778 template < typename ARRAY >
1779 inline ::collection::index push(ARRAY& a, typename ARRAY::BASE_ARG_TYPE newElement, ::collection::index n)
1780 {
1781
1782 return a.insert_at(a.get_upper_bound(n), newElement);
1783
1784 }
1785
1786
1787 template < typename ARRAY >
1788 inline void add(ARRAY& a, typename ARRAY::BASE_ARG_TYPE newElement, ::collection::index n)
1789 {
1790
1791 a.insert_at(a.get_upper_bound(n), newElement);
1792
1793 }
1794
1795
1796 } //namespace array
1797
1798
1799} // namespace acme
1800
1801
1802
1803
1804
1805namespace acme
1806{
1807
1808
1809 namespace array2d
1810 {
1811
1812 template < typename A >
1813 ::collection::count predominant_column_count(A& a)
1814 {
1815
1816 index_to_index column_count;
1817
1818 for (::collection::index i = 0; i < a.get_size(); i++)
1819 {
1820
1821 column_count[a[i].get_count()]++;
1822
1823 }
1824
1825 ::collection::count c = -1;
1826
1827 ::collection::count cMax = -1;
1828
1829 for (auto& assoc : column_count)
1830 {
1831
1832 if (assoc.element2() > cMax || (assoc.element2() == cMax && assoc.element1() > c))
1833 {
1834
1835 c = assoc.element1();
1836
1837 cMax = assoc.element2();
1838
1839 }
1840
1841 }
1842
1843 return c;
1844
1845 }
1846
1847
1848 } //namespace array2d
1849
1850
1851} // namespace acme
1852
1853
1854
::collection::index add(const pointer< T > &p)
consumes a referer
Definition pointer_array.h:226
include "aura/graphics/image/context.h"
Definition aaaa__defer.h:32