Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ahAlgo.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
33// Aleph implementation of C++ standard algorithms
34// Based on code from GNU ISO C++ Library, Hewlett-Packard and Silicon Graphics
35
36#ifndef AHALGO_H
37#define AHALGO_H
38
49#include <ahAssert.H>
50#include <ahUtils.H>
51
52namespace Aleph
53{
54
56
57// ============================================================================
58// Non-Modifying Algorithms
59// ============================================================================
60
75template <class Itor, class Operation>
76inline Operation for_each(Itor beg, const Itor & end, Operation op)
77{
78 while (beg != end)
79 op(*beg++);
80
81 return op;
82}
83
98template<class Itor, class Operation>
99[[nodiscard]] inline typename Itor::difference_type
100count_if(Itor beg, const Itor & end, Operation op)
101{
102 typename Itor::difference_type n = 0;
103
104 while (beg != end)
105 if (op(*beg++))
106 ++n;
107
108 return n;
109}
110
125template <class Itor, class T>
126[[nodiscard]] inline typename Itor::difference_type
127count(const Itor & beg, const Itor & end, const T & value)
128{
129 return Aleph::count_if(beg, end, Aleph::bind2nd(equal_to<T>(), value));
130}
131
146template<class Itor,
148[[nodiscard]] inline Itor min_element(Itor beg, const Itor & end,
149 CompFunc op = CompFunc())
150{
151 if (beg == end)
152 return end;
153
154 Itor min = beg;
155 ++beg;
156
157 while (beg != end)
158 {
159 if (op(*beg, *min))
160 min = beg;
161
162 ++beg;
163 }
164
165 return min;
166}
167
182template<class Itor,
184[[nodiscard]] inline Itor max_element(const Itor& beg, const Itor& end,
185 CompFunc op = CompFunc())
186{
187 return Aleph::min_element(beg, end, op);
188}
189
204template<class Itor, class UnaryPredicate>
205[[nodiscard]] inline Itor find_if(Itor beg, const Itor & end, UnaryPredicate op)
206{
207 while (beg != end and not op(*beg))
208 ++beg;
209
210 assert(beg == end or op(*beg));
211
212 return beg;
213}
214
229template<class Itor, class T>
230[[nodiscard]] inline Itor find(const Itor & beg, const Itor & end, const T & value)
231{
232 return Aleph::find_if(beg, end, Aleph::bind2nd(Aleph::equal_to<T>(), value));
233}
234
253template<class Itor, class Size, class T,
255[[nodiscard]] inline Itor search_n(Itor beg,
256 const Itor & end,
257 Size count,
258 const T & value,
260{
261 if (count <= 0 or beg == end)
262 return end;
263
264 Size i = 0;
265 Itor first;
266
267 while (beg != end and i < count)
268 {
269 if (op(*beg, value))
270 {
271 if (i == 0)
272 first = beg;
273 ++i;
274 }
275 else
276 i = 0;
277
278 ++beg;
279 }
280
281 if (i == count)
282 return first;
283
284 return end;
285}
286
307template<class Itor1, class Itor2,
309[[nodiscard]] inline Itor1 search(Itor1 beg, const Itor1 & end,
310 Itor2 searchBeg, const Itor2 & searchEnd,
312{
313 if (beg == end or searchBeg == searchEnd)
314 return end;
315
316 Itor1 first;
318 int count = 0;
319
320 while (beg != end and pivot != searchEnd)
321 {
322 if (op(*beg, *pivot))
323 {
324 if (count == 0)
325 first = beg;
326
327 ++pivot;
328 ++count;
329 }
330 else
331 {
333 count = 0;
334 }
335
336 ++beg;
337 }
338
339 if (pivot == searchEnd)
340 return first;
341
342 return end;
343}
344
362template<class Itor1, class Itor2,
367{
368 if (beg == end or searchBeg == searchEnd)
369 return end;
370
371 Itor1 ret_val = end;
372 while (true)
373 {
375 if (new_ret == end)
376 return ret_val;
377 else
378 {
380 beg = new_ret;
381 ++beg;
382 }
383 }
384}
385
403template<class Itor1, class Itor2,
405[[nodiscard]] inline Itor1 find_first_of(const Itor1& beg, const Itor1& end,
408{
409 while (searchBeg != searchEnd)
410 {
411 Itor1 current = beg;
412
413 while (current != end)
414 {
415 if (op(*current, *searchBeg))
416 return current;
417
418 ++current;
419 }
420
421 ++searchBeg;
422 }
423
424 return end;
425}
426
441template<class Itor,
443[[nodiscard]] inline Itor adjacent_find(Itor beg, const Itor & end,
445{
446 if (beg == end)
447 return end;
448
449 Itor next(beg);
450 ++next;
451
452 while (next != end)
453 {
454 if (op(*beg, *next))
455 return beg;
456
457 ++beg;
458 ++next;
459 }
460
461 return end;
462}
463
480template <class Itor1, class Itor2,
482[[nodiscard]] inline bool equal(Itor1 beg, const Itor1 & end,
484{
485 while (beg != end)
486 {
487 if (not op(*beg, *cmpBeg))
488 return false;
489
490 ++beg;
491 ++cmpBeg;
492 }
493
494 return true;
495}
496
513template <class Itor1, class Itor2,
515[[nodiscard]] inline std::pair<Itor1, Itor2>
516mismatch(Itor1 beg, const Itor1& end,
517 Itor2 cmpBeg,
519{
520 while (beg != end and op(*beg, *cmpBeg))
521 {
522 ++beg;
523 ++cmpBeg;
524 }
525
526 return std::make_pair(beg, cmpBeg);
527}
528
545template <class Itor1, class Itor2,
548 Itor2 beg2, const Itor2 & end2,
549 Comp op = Comp())
550{
551 while (beg1 != end1 and beg2 != end2)
552 {
553 if (op(*beg1, *beg2))
554 return true;
555 else if (op(*beg2, *beg1))
556 return false;
557
558 ++beg1;
559 ++beg2;
560 }
561
562 return beg1 == end1 and beg2 != end2;
563}
564
565
566// ============================================================================
567// Modifying Algorithms
568// ============================================================================
569
583template <class Itor1, class Itor2>
585{
586 while (sourceBeg != sourceEnd)
587 *destBeg++ = *sourceBeg++;
588
589 return destBeg;
590}
591
606template <class Itor1, class Itor2>
608{
609 while (sourceBeg != sourceEnd)
610 *--destEnd = *--sourceEnd;
611
612 return destEnd;
613}
614
631template <class Itor1, class Itor2, class UnaryFunc>
634{
635 while (sourceBeg != sourceEnd)
636 *destBeg++ = op(*sourceBeg++);
637
638 return destBeg;
639}
640
659template <class Itor1, class Itor2, class Itor3, class BinaryFunc>
662 Itor3 destBeg,
663 BinaryFunc op)
664{
665 while (source1Beg != source1End)
666 *destBeg++ = op(*source1Beg++, *source2Beg++);
667
668 return destBeg;
669}
670
685template <class Itor1, class Itor2>
687{
688 while (beg1 != end1)
689 std::swap(*beg1++, *beg2++);
690
691 return beg2;
692}
693
706template <class Itor, class T>
707inline void fill(Itor beg, const Itor& end, const T & value)
708{
709 while (beg != end)
710 *beg++ = value;
711}
712
726template <class Itor, class T, class Size>
727inline void fill_n(Itor beg, Size num, const T & value)
728{
729 while (num-- > 0)
730 *beg++ = value;
731}
732
745template <class Itor, class Func>
746inline void generate(Itor beg, const Itor& end, Func op)
747{
748 while (beg != end)
749 *beg++ = op();
750}
751
765template <class Itor, class Size, class Func>
766inline void generate_n(Itor beg, Size num, Func op)
767{
768 while (num-- > 0)
769 *beg++ = op();
770}
771
787template <class Itor, class UnaryPredicate, class T>
788inline void replace_if(Itor beg, const Itor& end,
789 UnaryPredicate op,
790 const T & value)
791{
792 while (beg != end)
793 {
794 if (op(*beg))
795 *beg = value;
796
797 ++beg;
798 }
799}
800
814template <class Itor, class T>
815inline void replace(Itor beg, const Itor& end,
816 const T & old_value,
817 const T & new_value)
818{
821}
822
841template <class Itor1, class Itor2, class UnaryPredicate, class T>
843 Itor2 destBeg,
844 UnaryPredicate op,
845 const T & value)
846{
847 while (sourceBeg != sourceEnd)
848 {
849 if (op(*sourceBeg))
850 *destBeg++ = value;
851 else
852 *destBeg++ = *sourceBeg;
853
854 ++sourceBeg;
855 }
856
857 return destBeg;
858}
859
877template <class Itor1, class Itor2, class T>
887
904template <class In_Itor, class Out_Itor, class Predicate>
908{
909 for ( ; __first != __last; ++__first)
910 if (not __pred(*__first))
911 {
912 *__result = *__first;
913 ++__result;
914 }
915
916 return __result;
917}
918
933template<class Fw_Itor, class Predicate>
936{
938
940
941 if (__first == __last)
942 return __first;
943 else
945}
946
961template<class Fw_Itor, class T>
968
970template<class In_Itor, class Out_Itor,
975{
976 typename In_Itor::value_type __value = *__first;
977
978 *__result = __value;
979
980 while (++__first != __last)
982 {
983 __value = *__first;
984 *++__result = __value;
985 }
986
987 return ++__result;
988}
990
1005template<class In_Itor, class Out_Itor>
1008{
1009 if (__first == __last)
1010 return __result;
1011
1013}
1014
1031template <class In_Itor, class Out_Itor, class BinaryPredicate>
1041
1056template<class Itor,
1058inline Itor unique(Itor __first, Itor __last,
1060{
1061 // Skip the beginning, if already unique.
1063
1064 if (__first == __last)
1065 return __last;
1066
1067 // Do the real copy work.
1068 Itor __dest = __first;
1069 ++__first;
1070
1071 while (++__first != __last)
1073 *++__dest = *__first;
1074
1075 return ++__dest;
1076}
1077
1078
1079// ============================================================================
1080// Mutating Algorithms
1081// ============================================================================
1082
1093template <class Itor>
1094inline void reverse(Itor beg, Itor end)
1095{
1096 while (beg != end and beg != --end)
1097 std::swap(*beg++, *end);
1098}
1099
1113template <class Itor1, class Itor2>
1115{
1116 while (sourceBeg != sourceEnd)
1117 {
1118 --sourceEnd;
1119 *destBeg = *sourceEnd;
1120 ++destBeg;
1121 }
1122
1123 return destBeg;
1124}
1125
1137template <class Itor>
1138inline void rotate(Itor beg, Itor pos, Itor end)
1139{
1140 Aleph::reverse(beg, pos);
1141 Aleph::reverse(pos, end);
1142 Aleph::reverse(beg, end);
1143}
1144
1160template <class Itor1, class Itor2>
1161inline Itor2 rotate_copy(const Itor1& beg, const Itor1& pos, const Itor1& end,
1162 Itor2 tgt_beg)
1163{
1164 return Aleph::copy(beg, pos, Aleph::copy(pos, end, tgt_beg));
1165}
1166
1167
1168// ============================================================================
1169// Sorted Range Algorithms
1170// ============================================================================
1171
1189template <class Itor, class T>
1190[[nodiscard]] inline Itor lower_bound(Itor beg, Itor end, const T& value)
1191{
1192 while (beg != end and *beg < value)
1193 ++beg;
1194
1195 return beg;
1196}
1197
1214template <class Itor, class T, class BinaryPredicate>
1215[[nodiscard]] inline Itor lower_bound(Itor beg, Itor end, const T& value,
1216 BinaryPredicate op)
1217{
1218 while (beg != end and op(*beg, value))
1219 ++beg;
1220
1221 return beg;
1222}
1223
1238template <class Itor, class T>
1239[[nodiscard]] inline Itor upper_bound(Itor beg, Itor end, const T& value)
1240{
1241 while (beg != end and not (value < *beg))
1242 ++beg;
1243
1244 return beg;
1245}
1246
1260template <class Itor, class T, class BinaryPredicate>
1261[[nodiscard]] inline Itor upper_bound(Itor beg, Itor end, const T& value,
1262 BinaryPredicate op)
1263{
1264 while (beg != end and (op(*beg, value) or not op(value, *beg)))
1265 ++beg;
1266
1267 return beg;
1268}
1269
1283template<class Itor, class T>
1284[[nodiscard]] inline bool binary_search(Itor beg, Itor end, const T& value)
1285{
1286 Itor i = Aleph::lower_bound(beg, end, value);
1287 return i != end and not (value < *i);
1288}
1289
1306template<class Itor, class T, class BinaryPredicate>
1307[[nodiscard]] inline bool binary_search(Itor beg, Itor end, const T& value,
1308 BinaryPredicate op)
1309{
1310 Itor i = Aleph::lower_bound(beg, end, value, op);
1311 return i != end and not op(value, *i);
1312}
1313
1328template <class Itor, class T>
1329[[nodiscard]] inline std::pair<Itor, Itor>
1330equal_range(Itor beg, Itor end, const T& value)
1331{
1332 return std::make_pair(Aleph::lower_bound(beg, end, value),
1333 Aleph::upper_bound(beg, end, value));
1334}
1335
1349template <class Itor, class T, class BinaryPredicate>
1350[[nodiscard]] inline std::pair<Itor, Itor>
1351equal_range(Itor beg, Itor end, const T& value, BinaryPredicate op)
1352{
1353 return std::make_pair(Aleph::lower_bound(beg, end, value, op),
1354 Aleph::upper_bound(beg, end, value, op));
1355}
1356
1372template <class Itor1, class Itor2>
1373[[nodiscard]] inline bool includes(Itor1 beg, Itor1 end,
1375{
1376 while (beg != end and searchBeg != searchEnd)
1377 {
1378 if (*searchBeg < *beg)
1379 return false;
1380 else if (*beg < *searchBeg)
1381 ++beg;
1382 else
1383 {
1384 ++beg;
1385 ++searchBeg;
1386 }
1387 }
1388
1389 return searchBeg == searchEnd;
1390}
1391
1409template <class Itor1, class Itor2, class Itor3>
1412 Itor3 destBeg)
1413{
1415 {
1416 if (*source2Beg < *source1Beg)
1417 {
1418 *destBeg = *source2Beg;
1419 ++source2Beg;
1420 }
1421 else
1422 {
1423 *destBeg = *source1Beg;
1424 ++source1Beg;
1425 }
1426 ++destBeg;
1427 }
1430}
1431
1451template <class Itor1, class Itor2, class Itor3, class BinaryPredicate>
1455{
1457 {
1458 if (op(*source2Beg, *source1Beg))
1459 {
1460 *destBeg = *source2Beg;
1461 ++source2Beg;
1462 }
1463 else
1464 {
1465 *destBeg = *source1Beg;
1466 ++source1Beg;
1467 }
1468 ++destBeg;
1469 }
1472}
1473
1474
1475// ============================================================================
1476// Numeric Algorithms
1477// ============================================================================
1478
1492template <class Itor, class T>
1493[[nodiscard]] inline T accumulate(Itor beg, Itor end, T initValue)
1494{
1495 for ( ; beg != end; ++beg)
1496 initValue = initValue + *beg;
1497
1498 return initValue;
1499}
1500
1517template <class Itor, class T, class BinaryFunc>
1518[[nodiscard]] inline T accumulate(Itor beg, Itor end, T initValue, BinaryFunc op)
1519{
1520 for ( ; beg != end; ++beg)
1521 initValue = op(initValue, *beg);
1522
1523 return initValue;
1524}
1525
1542template <class Itor1, class Itor2, class T>
1544{
1545 for ( ; beg1 != end1; ++beg1, ++beg2)
1546 initValue = initValue + (*beg1 * *beg2);
1547
1548 return initValue;
1549}
1550
1571template <class Itor1, class Itor2, class T, class BinaryFunc1, class BinaryFunc2>
1574{
1575 for ( ; beg1 != end1; ++beg1, ++beg2)
1577
1578 return initValue;
1579}
1580
1595template <class Itor1, class Itor2>
1597{
1598 if (sourceBeg == sourceEnd)
1599 return destBeg;
1600
1601 typename Itor1::value_type sum = *sourceBeg;
1602 *destBeg = sum;
1603 ++sourceBeg;
1604 ++destBeg;
1605
1606 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1607 {
1608 sum = sum + *sourceBeg;
1609 *destBeg = sum;
1610 }
1611
1612 return destBeg;
1613}
1614
1630template <class Itor1, class Itor2, class BinaryFunc>
1633{
1634 if (sourceBeg == sourceEnd)
1635 return destBeg;
1636
1637 typename Itor1::value_type sum = *sourceBeg;
1638 *destBeg = sum;
1639 ++sourceBeg;
1640 ++destBeg;
1641
1642 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1643 {
1644 sum = op(sum, *sourceBeg);
1645 *destBeg = sum;
1646 }
1647
1648 return destBeg;
1649}
1650
1666template <class Itor1, class Itor2>
1668{
1669 if (sourceBeg == sourceEnd)
1670 return destBeg;
1671
1672 typename Itor1::value_type prev = *sourceBeg;
1673 *destBeg = prev;
1674 ++sourceBeg;
1675 ++destBeg;
1676
1677 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1678 {
1679 typename Itor1::value_type curr = *sourceBeg;
1680 *destBeg = curr - prev;
1681 prev = curr;
1682 }
1683
1684 return destBeg;
1685}
1686
1702template <class Itor1, class Itor2, class BinaryFunc>
1705{
1706 if (sourceBeg == sourceEnd)
1707 return destBeg;
1708
1709 typename Itor1::value_type prev = *sourceBeg;
1710 *destBeg = prev;
1711 ++sourceBeg;
1712 ++destBeg;
1713
1714 for ( ; sourceBeg != sourceEnd; ++sourceBeg, ++destBeg)
1715 {
1716 typename Itor1::value_type curr = *sourceBeg;
1717 *destBeg = op(curr, prev);
1718 prev = curr;
1719 }
1720
1721 return destBeg;
1722}
1723
1724} // end namespace Aleph
1725
1726#endif // AHALGO_H
Debug assertion and warning utilities.
General utility functions and helpers.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4111
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Itor lower_bound(Itor beg, Itor end, const T &value)
Find lower bound in a sorted range.
Definition ahAlgo.H:1190
std::pair< Itor1, Itor2 > mismatch(Itor1 beg, const Itor1 &end, Itor2 cmpBeg, BinaryPredicate op=BinaryPredicate())
Find the first mismatching elements in two ranges.
Definition ahAlgo.H:516
void reverse(Itor beg, Itor end)
Reverse elements in a range.
Definition ahAlgo.H:1094
Itor unique(Itor __first, Itor __last, BinaryPredicate __binary_pred=BinaryPredicate())
Remove consecutive duplicates in place.
Definition ahAlgo.H:1058
Itor2 partial_sum(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
Compute partial sums of a range.
Definition ahAlgo.H:1596
Itor2 copy_backward(const Itor1 &sourceBeg, Itor1 sourceEnd, Itor2 destEnd)
Copy elements backward from one range to another.
Definition ahAlgo.H:607
Itor1 find_end(Itor1 beg, Itor1 end, Itor2 searchBeg, Itor2 searchEnd, BinaryPredicate op=BinaryPredicate())
Find the last occurrence of a subrange.
Definition ahAlgo.H:364
void generate(Itor beg, const Itor &end, Func op)
Generate values for a range.
Definition ahAlgo.H:746
T inner_product(Itor1 beg1, Itor1 end1, Itor2 beg2, T initValue)
Compute inner product of two ranges.
Definition ahAlgo.H:1543
binder2nd< _Operation > bind2nd(const _Operation &__fn, const _Tp &__x)
Definition ahFunction.H:375
void replace_if(Itor beg, const Itor &end, UnaryPredicate op, const T &value)
Replace elements satisfying a predicate.
Definition ahAlgo.H:788
Out_Itor unique_copy(In_Itor __first, In_Itor __last, Out_Itor __result)
Copy unique elements.
Definition ahAlgo.H:1006
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
bool lexicographical_compare(Itor1 beg1, const Itor1 &end1, Itor2 beg2, const Itor2 &end2, Comp op=Comp())
Lexicographical comparison of two ranges.
Definition ahAlgo.H:547
void fill(Itor beg, const Itor &end, const T &value)
Fill a range with a value.
Definition ahAlgo.H:707
Out_Itor remove_copy_if(In_Itor __first, const In_Itor &__last, Out_Itor __result, Predicate __pred)
Copy elements not satisfying a predicate.
Definition ahAlgo.H:905
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:107
size_t size_type
Definition ahAlgo.H:55
Itor2 adjacent_difference(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
Compute adjacent differences.
Definition ahAlgo.H:1667
Itor adjacent_find(Itor beg, const Itor &end, BinaryPredicate op=BinaryPredicate())
Find first pair of adjacent equal elements.
Definition ahAlgo.H:443
T accumulate(Itor beg, Itor end, T initValue)
Accumulate values in a range.
Definition ahAlgo.H:1493
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
Definition ahAlgo.H:230
Itor2 swap_ranges(Itor1 beg1, const Itor1 &end1, Itor2 beg2)
Swap elements between two ranges.
Definition ahAlgo.H:686
Itor min_element(Itor beg, const Itor &end, CompFunc op=CompFunc())
Find the minimum element in a range.
Definition ahAlgo.H:148
Itor2 replace_copy_if(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg, UnaryPredicate op, const T &value)
Copy and replace elements satisfying a predicate.
Definition ahAlgo.H:842
Itor upper_bound(Itor beg, Itor end, const T &value)
Find upper bound in a sorted range.
Definition ahAlgo.H:1239
Fw_Itor remove(Fw_Itor __first, const Fw_Itor &__last, const T &__value)
Remove elements equal to a value.
Definition ahAlgo.H:962
Itor search_n(Itor beg, const Itor &end, Size count, const T &value, BinaryPredicate op=BinaryPredicate())
Find n consecutive elements equal to a value.
Definition ahAlgo.H:255
Itor1 search(Itor1 beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Search for a subrange within a range.
Definition ahAlgo.H:309
bool equal(Itor1 beg, const Itor1 &end, Itor2 cmpBeg, BinaryPredicate op=BinaryPredicate())
Test if two ranges are equal.
Definition ahAlgo.H:482
Itor2 transform(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg, UnaryFunc op)
Transform elements using a unary operation.
Definition ahAlgo.H:632
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
Definition ahAlgo.H:76
void fill_n(Itor beg, Size num, const T &value)
Fill n elements with a value.
Definition ahAlgo.H:727
Itor1 find_first_of(const Itor1 &beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Find first element from a set.
Definition ahAlgo.H:405
Itor2 replace_copy(const Itor1 &sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg, const T &old_value, const T &new_value)
Copy and replace elements equal to a value.
Definition ahAlgo.H:878
Fw_Itor remove_if(Fw_Itor __first, const Fw_Itor &__last, Predicate __pred)
Remove elements satisfying a predicate.
Definition ahAlgo.H:934
Itor3 merge(Itor1 source1Beg, Itor1 source1End, Itor2 source2Beg, Itor2 source2End, Itor3 destBeg)
Merge two sorted ranges.
Definition ahAlgo.H:1410
bool binary_search(Itor beg, Itor end, const T &value)
Binary search for a value.
Definition ahAlgo.H:1284
Itor::difference_type count_if(Itor beg, const Itor &end, Operation op)
Count elements satisfying a predicate.
Definition ahAlgo.H:100
void generate_n(Itor beg, Size num, Func op)
Generate values for n elements.
Definition ahAlgo.H:766
bool includes(Itor1 beg, Itor1 end, Itor2 searchBeg, Itor2 searchEnd)
Test if one sorted range includes another.
Definition ahAlgo.H:1373
std::pair< Itor, Itor > equal_range(Itor beg, Itor end, const T &value)
Find equal range in a sorted sequence.
Definition ahAlgo.H:1330
Itor2 reverse_copy(Itor1 sourceBeg, Itor1 sourceEnd, Itor2 destBeg)
Copy elements in reverse order.
Definition ahAlgo.H:1114
void next()
Advance all underlying iterators (bounds-checked).
Definition ah-zip.H:175
Itor max_element(const Itor &beg, const Itor &end, CompFunc op=CompFunc())
Find the maximum element in a range.
Definition ahAlgo.H:184
void replace(Itor beg, const Itor &end, const T &old_value, const T &new_value)
Replace elements equal to a value.
Definition ahAlgo.H:815
Itor find_if(Itor beg, const Itor &end, UnaryPredicate op)
Find the first element satisfying a predicate.
Definition ahAlgo.H:205
void rotate(Itor beg, Itor pos, Itor end)
Rotate elements in a range.
Definition ahAlgo.H:1138
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Itor2 rotate_copy(const Itor1 &beg, const Itor1 &pos, const Itor1 &end, Itor2 tgt_beg)
Copy and rotate elements.
Definition ahAlgo.H:1161