ListOps.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 InNamespace
28  Foam
29 
30 Description
31  Various functions to operate on Lists.
32 
33 Namespace
34  Foam::ListOps
35 
36 Description
37  Various utility functions to work on Lists.
38 
39 SourceFiles
40  ListOps.C
41  ListOpsTemplates.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_ListOps_H
46 #define Foam_ListOps_H
47 
48 #include "FlatOutput.H"
49 #include "labelPair.H"
50 #include "labelList.H"
51 #include "IndirectList.H"
52 #include "HashSet.H"
53 #include "Map.H"
54 #include "bitSet.H"
55 #include "ops.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 template<class T> class CompactListList;
64 
65 
66 //- Renumber the values within a list.
67 // Negative input values are left untouched.
68 template<class IntListType>
69 IntListType renumber(const labelUList& oldToNew, const IntListType& input);
70 
71 //- Inplace renumber the values within a list.
72 // Negative input values are left untouched.
73 template<class IntListType>
74 void inplaceRenumber(const labelUList& oldToNew, IntListType& input);
75 
76 //- Inplace renumber the values of a list.
77 // Values that are not mapped by oldToNew are left untouched.
78 template<class IntListType>
79 void inplaceRenumber(const Map<label>& oldToNew, IntListType& input);
80 
81 
82 //- Reorder the elements of a list.
83 // Locations with negative oldToNew values are left as is (copy-through).
84 // However, if pruning is activated, these negative oldToNew values are
85 // instead skipped over and the resulting list shrunk to the max index
86 // actually used.
87 template<class ListType>
88 ListType reorder
89 (
90  const labelUList& oldToNew,
91  const ListType& input,
92  const bool prune = false
93 );
94 
95 //- Inplace reorder the elements of a list.
96 // Locations with negative oldToNew values are left as is (copy-through).
97 // However, if pruning is activated, these negative oldToNew values are
98 // instead skipped over and the resulting list shrunk to the max index
99 // actually used.
100 template<class ListType>
101 void inplaceReorder
102 (
103  const labelUList& oldToNew,
104  ListType& input,
105  const bool prune = false
106 );
107 
108 
109 //- Reorder the elements of a packed list.
110 // Similar to the general templated form, but with auto-vivify
111 // for PackedList.
112 template<unsigned Width>
113 PackedList<Width> reorder
114 (
115  const labelUList& oldToNew,
116  const PackedList<Width>& input,
117  const bool prune = false
118 );
119 
120 //- Inplace reorder the elements of a packed list.
121 // Similar to the general templated form, but with auto-vivify
122 // for PackedList.
123 template<unsigned Width>
124 void inplaceReorder
125 (
126  const labelUList& oldToNew,
127  PackedList<Width>& input,
128  const bool prune = false
129 );
130 
131 
132 //- Reorder the elements of a list.
133 // Similar to the general templated form, but with auto-vivify for Bitset.
134 bitSet reorder
135 (
136  const labelUList& oldToNew,
137  const bitSet& input,
138  const bool prune = false
139 );
140 
141 //- Inplace reorder the elements of a list.
142 // Similar to the general templated form, but with auto-vivify for bitSet.
143 void inplaceReorder
144 (
145  const labelUList& oldToNew,
146  bitSet& input,
147  const bool prune = false
148 );
149 
150 
151 //- Rewrite with mapped keys. Ignore elements with negative key.
152 // The Container is some type of HashTable or Map with a label for its key.
153 template<class Container>
154 void inplaceMapKey(const labelUList& oldToNew, Container& input);
155 
156 //- Map values. Ignore negative values.
157 // \return number of values changed
158 template<class Container>
159 label inplaceMapValue(const labelUList& oldToNew, Container& input);
160 
161 //- Use mapper as a lookup to modify the values of input.
162 //
163 // \return number of values changed
164 //
165 // \code
166 // Map<label> mapper({{1, 3}, {2, 6}, {3, 12}, {5, 8}});
167 //
168 // HashTable<label> models with
169 // {
170 // model0 => 1,
171 // model1 => 4,
172 // model2 => 5,
173 // }
174 //
175 // inplaceMapValue(mapper, models);
176 //
177 // Now contains
178 // {
179 // model0 => 3,
180 // model1 => 4,
181 // model2 => 8,
182 // }
183 // \endcode
184 //
185 // \note the modification occurs in a single pass and will not
186 // remap more than once.
187 template<class Container>
188 label inplaceMapValue(const Map<label>& mapper, Container& input);
189 
190 
191 //- Return (sorted) indices corresponding to duplicate list values
192 template<class T>
193 labelList duplicateOrder(const UList<T>& input);
194 
195 //- Generate (sorted) indices corresponding to duplicate list values
196 template<class T>
197 void duplicateOrder(const UList<T>& input, labelList& order);
198 
199 //- Generate (sorted) indices corresponding to duplicate list values
200 // sort using specified list compare predicate
201 template<class T, class ListComparePredicate>
202 void duplicateOrder
203 (
204  const UList<T>& input,
205  labelList& order,
206  const ListComparePredicate& comp
207 );
208 
209 
210 //- Return (sorted) indices corresponding to unique list values
211 template<class T>
212 labelList uniqueOrder(const UList<T>& input);
213 
214 //- Generate (sorted) indices corresponding to unique list values
215 template<class T>
216 void uniqueOrder(const UList<T>& input, labelList& order);
217 
218 //- Generate (sorted) indices corresponding to unique list values
219 // sort using specified list compare predicate
220 template<class T, class ListComparePredicate>
221 void uniqueOrder
222 (
223  const UList<T>& input,
224  labelList& order,
225  const ListComparePredicate& comp
226 );
227 
228 
229 //- Return sorted list with removal of duplicates
230 template<class T>
231 List<T> uniqueSort(const UList<T>& input);
232 
233 //- Inplace sorting and removal of duplicates.
234 // Do not use FixedList for the input list, since it doesn't resize.
235 template<class ListType>
236 void inplaceUniqueSort(ListType& input);
237 
238 //- Inplace sorting and removal of duplicates.
239 // Do not use FixedList for the input list, since it doesn't resize.
240 template<class ListType, class ListComparePredicate>
242 (
243  ListType& input,
244  const ListComparePredicate& comp
245 );
246 
247 
248 //- Extract elements of the input list when select is true.
249 //
250 // \param[in] select the bool-list selector, for which the operator[]
251 // returns true or false. A labelHashSet can also be used since
252 // it satisfies these requirements
253 // \param[in] input the list input values.
254 // \param[in] invert set as true to invert the selection logic
255 //
256 // Eg, to extract all selected elements:
257 // \code
258 // subset<boolList, labelList>(selectedElems, list);
259 // \endcode
260 //
261 // \return The subsetted list
262 // \see IndirectList::subset
263 template<class BoolListType, class T>
264 List<T> subset
265 (
266  const BoolListType& select,
267  const UList<T>& input,
268  const bool invert=false
269 );
270 
271 //- Extract elements of the input list when select is true.
272 //
273 // \param[in] select the selection as a bitSet.
274 // \param[in] input the list input values.
275 // \param[in] invert set as true to invert the selection logic
276 //
277 // \return The subsetted list
278 // \see IndirectList::subset
279 template<class T>
280 List<T> subset
281 (
282  const bitSet& select,
283  const UList<T>& input,
284  const bool invert=false
285 );
286 
287 //- Inplace extract elements of the input list when select is true.
288 //
289 // \param[in] select the bool-list selector, for which the operator[]
290 // returns true or false. A labelHashSet can also be used since
291 // it satisfies these requirements
292 // \param[in,out] input the list input values.
293 // Cannot be a FixedList since it doesn't resize.
294 // \param[in] invert set as true to invert the selection logic
295 template<class BoolListType, class ListType>
296 void inplaceSubset
297 (
298  const BoolListType& select,
299  ListType& input,
300  const bool invert=false
301 );
302 
303 //- Inplace extract elements of the input list when select is true.
304 //
305 // \param[in] select the selection as a bitSet.
306 // \param[in,out] input the list input values.
307 // Cannot be a FixedList since it doesn't resize.
308 // \param[in] invert set as true to invert the selection logic
309 //
310 // \note Includes optimized handling of bitSet when invert=false.
311 template<class ListType>
312 void inplaceSubset
313 (
314  const bitSet& select,
315  ListType& input,
316  const bool invert=false
317 );
318 
319 //- Copy a subset of the input list when predicate is true.
320 //
321 // \param[in] input the list input values.
322 // \param[in] pred the selection predicate
323 // \param[in] invert set as true to invert the selection logic
324 //
325 // \return The subsetted list
326 // \see IndirectList::subset_if
327 template<class T, class UnaryPredicate>
328 List<T> subsetList
329 (
330  const UList<T>& input,
331  const UnaryPredicate& pred,
332  const bool invert=false
333 );
334 
335 
336 //- Inplace subset of the list when predicate is true.
337 //
338 // \param[in,out] input the list input/output values.
339 // Cannot be a FixedList since it doesn't resize.
340 // \param[in] pred the selection predicate
341 // \param[in] invert set as true to invert the selection logic
342 template<class ListType, class UnaryPredicate>
344 (
345  ListType& input,
346  const UnaryPredicate& pred,
347  const bool invert=false
348 );
349 
350 
351 //- Create an inverse one-to-one mapping.
352 // \param len the output size
353 // \param map the unique indices to map, in a [0..len) range.
354 // Any negative indices are ignored.
355 //
356 // \return the inverse mapping with -1 for unmapped elements.
357 labelList invert(const label len, const labelUList& map);
358 
359 //- Create an inverse one-to-one mapping for all 'on' bits of the map.
360 // \param len the output size
361 // \param map the 'on' bits to use for the mapping indices.
362 // The last on bit shall be less than len.
363 //
364 // \return the inverse mapping with -1 for unmapped elements.
365 labelList invert(const label len, const bitSet& map);
366 
367 //- Create an inverse one-to-one mapping for all 'on' bits of the map.
368 // The output size is dictated by the map size.
369 // \param map the unique indices to map.
370 //
371 // \return the inverse mapping with -1 for unmapped elements.
372 labelList invert(const bitSet& map);
373 
374 //- Create inverse mapping, which is a lookup table into the given list
375 // \param values the values (likely unique).
376 //
377 // Negative values are allowed, duplicates are "first wins"
378 //
379 // \return the inverse lookup
380 Map<label> invertToMap(const labelUList& values);
381 
382 //- Invert one-to-many map. Unmapped elements will be size 0.
383 labelListList invertOneToMany(const label len, const labelUList& map);
384 
385 //- Invert one-to-many compact map. Unmapped elements will be size 0.
386 CompactListList<label> invertOneToManyCompact
387 (
388  const label len,
389  const labelUList& map
390 );
391 
392 //- Invert many-to-many.
393 // Input and output types must be inherited from List and also
394 // contain ints/labels. Used, for example, for faces to pointFaces.
395 template<class InputIntListType, class OutputIntListType>
396 void invertManyToMany
397 (
398  const label len,
399  const UList<InputIntListType>& input,
400  List<OutputIntListType>& output
401 );
402 
403 template<class InputIntListType, class OutputIntListType>
404 List<OutputIntListType> invertManyToMany
405 (
406  const label len,
407  const UList<InputIntListType>& input
408 )
409 {
410  List<OutputIntListType> output;
411  invertManyToMany<InputIntListType,OutputIntListType>(len, input, output);
412  return output;
413 }
414 
415 
416 //- Deprecated(2017-10) search for first occurrence of the given element.
417 // \return The index found or return -1 if not found.
418 // \deprecated(2017-10) - use the UList find/found methods
419 template<class ListType>
420 FOAM_DEPRECATED_FOR(2017-10, "UList find/found methods")
421 label findIndex
422 (
423  const ListType& input,
424  typename ListType::const_reference val,
425  const label start=0
426 )
427 {
428  return input.find(val, start);
429 }
430 
431 
432 //- Linear search to find all occurrences of given element.
433 template<class ListType>
435 (
436  const ListType& input,
437  typename ListType::const_reference val,
438  label start=0
439 );
440 
441 
442 //- Linear search for the index of the min element,
443 //- similar to std::min_element but for lists and returns the index.
444 //
445 // \tparam ListType The input list type
446 //
447 // \param input The list to search
448 // \param start The start index in the list (default: 0)
449 //
450 // \return The min index or -1 on error.
451 template<class ListType>
452 label findMin(const ListType& input, label start=0);
453 
454 //- Linear search for the index of the max element,
455 //- similar to std::max_element but for lists and returns the index.
456 //
457 // \tparam ListType The input list type
458 //
459 // \param input The list to search
460 // \param start The start index in the list (default: 0)
461 //
462 // \return The max index or -1 on error.
463 template<class ListType>
464 label findMax(const ListType& input, label start=0);
465 
466 
467 //- Linear search for the index of the min/max element,
468 //- similar to std::minmax_element but for lists and returns the index.
469 //
470 // \tparam ListType The input list type
471 //
472 // \param input The list to search
473 // \param start The start index in the list (default: 0)
474 //
475 // \return The min/max indices as a Pair (min is first max is second)
476 // or (-1,-1) on error.
477 template<class ListType>
478 labelPair findMinMax(const ListType& input, label start=0);
479 
480 
481 //- Binary search to find the index of the last element in a sorted list
482 //- that is less than value.
483 //
484 // Uses the global <code> < </code> operator and thus
485 // <code> (list[i] < val) </code> for the test.
486 //
487 // \tparam ListType The input list type
488 // \tparam T The value type (should normally be ListType::value_type)
489 //
490 // \param input The sorted list to search
491 // \param val The value for searching/comparing
492 // \param start The start index in the list (default: 0)
493 //
494 // \return The index found or -1 if not found.
495 template<class ListType>
496 label findSortedIndex
497 (
498  const ListType& input,
499  typename ListType::const_reference val,
500  const label start=0
501 );
502 
503 
504 //- Binary search to find the index of the last element in a sorted list
505 //- that is less than value.
506 //
507 // Uses <code> lessOp<T>() </code> and thus
508 // <code> lessOp<T>(list[i], val) </code> for the test.
509 //
510 // \tparam ListType The input list type
511 // \tparam T The value type (is often the same as ListType::value_type)
512 // \tparam ComparePredicate The type of the comparison functor that
513 // returns true for sorting below.
514 //
515 // \param input The sorted list to search
516 // \param val The value for searching/comparing
517 // \param start The start index in the list
518 // \param comp The comparison functor for testing.
519 // Uses <code> comp(list[i], val) </code> for the test.
520 //
521 // \return The index found or -1 if not found.
522 template<class ListType, class T, class ComparePredicate>
523 label findLower
524 (
525  const ListType& input,
526  const T& val,
527  const label start,
528  const ComparePredicate& comp
529 );
530 
531 
532 //- Binary search to find the index of the last element in a sorted list
533 //- that is less than value.
534 //
535 // Uses <code> lessOp<T>() </code> and thus
536 // <code> lessOp<T>(list[i], val) </code> for the test.
537 //
538 // \tparam ListType The input list type
539 // \tparam T The value type (should normally be ListType::value_type)
540 //
541 // \param input The sorted list to search
542 // \param val The value for searching/comparing
543 // \param start The start index in the list (default: 0)
544 //
545 // \return The index found or -1 if not found.
546 template<class ListType, class T>
547 label findLower
548 (
549  const ListType& input,
550  const T& val,
551  const label start=0
552 );
553 
554 
555 //- Reverse a list. First element becomes last element etc.
556 template<class ListType>
557 ListType reverseList(const ListType& input);
558 
559 
560 //- Inplace reversal of a list using Swap.
561 template<class ListType>
562 void inplaceReverseList(ListType& input);
563 
564 
565 //- Rotate a list by n places.
566 // If n is positive rotate clockwise/right/down.
567 // If n is negative rotate anti-clockwise/left/up.
568 template<class ListType>
569 ListType rotateList(const ListType& list, const label n);
570 
571 
572 //- Inplace reversal of a list using the Reversal Block Swapping algorithm.
573 template<template<typename> class ListType, class DataType>
574 void inplaceRotateList(ListType<DataType>& list, label n);
575 
576 
577 /*---------------------------------------------------------------------------*\
578  Namespace ListOps Declaration
579 \*---------------------------------------------------------------------------*/
580 
581 namespace ListOps
582 {
583 
584 //- List helper to append y elements onto the end of x
585 template<class T>
586 struct appendEqOp
587 {
588  void operator()(List<T>& x, const List<T>& y) const;
589 };
590 
591 //- List helper to append y unique elements onto the end of x
592 template<class T>
593 struct uniqueEqOp
594 {
595  void operator()(List<T>& x, const List<T>& y) const;
596 };
597 
598 //- List helper to add y unique elements to x
599 struct unionEqOp
600 {
601  void operator()(labelList& x, const labelList& y) const;
602 };
603 
604 
605 // Public classes
606 
607 //- A list compare binary predicate for normal sort
608 template<class ListType>
609 struct less
610 {
611  const ListType& values;
612 
613  less(const ListType& list)
614  :
615  values(list)
616  {}
617 
618  bool operator()(const label a, const label b) const
619  {
620  return (values[a] < values[b]);
621  }
622 };
623 
624 
625 //- A list compare binary predicate for reverse sort
626 template<class ListType>
627 struct greater
628 {
629  const ListType& values;
630 
631  greater(const ListType& list)
632  :
633  values(list)
634  {}
635 
636  bool operator()(const label a, const label b) const
637  {
638  return (values[b] < values[a]);
639  }
640 };
641 
642 
643 //- Fill an identity map with (map[i] == i)
644 // Optionally with an alternative start index, so that (map[i] == i+start)
645 FOAM_DEPRECATED_STRICT(2023-10, "Foam::identity(...)")
646 inline void identity(labelUList& map, label start = 0)
647 {
648  Foam::identity(map, start);
649 }
650 
651 
652 //- Count the number of matching entries.
653 // When start is specified, any occurrences before start are ignored.
654 // Linear search.
655 // Like std::count_if but works with list indexing
656 template<class ListType, class UnaryPredicate>
657 label count_if
658 (
659  const ListType& input,
660  const UnaryPredicate& pred,
661  const label start=0
662 );
663 
664 
665 //- Find index of the first occurrence that satisfies the predicate.
666 // When start is specified, any occurrences before start are ignored.
667 // Linear search.
668 // Like std::find_if but works with list indexing.
669 // \return position in list or -1 if not found.
670 template<class ListType, class UnaryPredicate>
671 label find_if
672 (
673  const ListType& input,
674  const UnaryPredicate& pred,
675  const label start=0
676 );
677 
678 
679 //- Same as ListOps::find_if
680 template<class ListType, class UnaryPredicate>
681 label find
682 (
683  const ListType& input,
684  const UnaryPredicate& pred,
685  const label start=0
686 )
687 {
688  return ListOps::find_if(input, pred, start);
689 }
690 
691 
692 //- True if there is a value in the list that satisfies the predicate.
693 // When start is specified, any occurrences before start are ignored.
694 // Linear search.
695 // \return true if found.
696 template<class ListType, class UnaryPredicate>
697 bool found_if
698 (
699  const ListType& input,
700  const UnaryPredicate& pred,
701  const label start=0
702 );
703 
704 
705 //- Same as found_if
706 template<class ListType, class UnaryPredicate>
707 bool found
708 (
709  const ListType& input,
710  const UnaryPredicate& pred,
711  const label start=0
712 )
713 {
714  return ListOps::found_if(input, pred, start);
715 }
716 
717 
718 //- Linear search to find all occurences of given element.
719 template<class ListType, class UnaryPredicate>
721 (
722  const ListType& input,
723  const UnaryPredicate& pred,
724  label start=0
725 );
726 
727 
728 //- Set various locations of the list with a specified value.
729 //
730 // \param list the list to modify
731 // \param locations where to apply the specified value
732 // An out-of-range index is silently ignored.
733 // \param val the value to set at the specified locations
734 template<class T>
735 void setValue
736 (
737  UList<T>& list,
738  const labelUList& locations,
739  const T& val
740 );
742 
743 //- Set various locations of the list with a specified value.
744 //
745 // \param list the list to modify
746 // \param locations where to apply the specified value
747 // An out-of-range index is silently ignored.
748 // \param val the value to set at the specified locations
749 template<class T>
751 (
752  UList<T>& list,
753  const labelHashSet& locations,
754  const T& val
755 );
756 
757 
758 //- Set various locations of the list with a specified value.
759 //
760 // \param list the list to modify
761 // \param locations where to apply the specified value
762 // An out-of-range index is silently ignored.
763 // \param val the value to set at the specified locations
764 template<class T>
766 (
767  UList<T>& list,
768  const UList<bool>& locations,
769  const T& val
770 );
771 
772 
773 //- Set various locations of the list with a specified value.
774 //
775 // \param list the list to modify
776 // \param locations where to apply the specified value
777 // An out-of-range index is silently ignored.
778 // \param val the value to set at the specified locations
779 template<class T>
780 void setValue
781 (
782  UList<T>& list,
783  const bitSet& locations,
784  const T& val
785 );
786 
787 
788 //- Create a List from a List of a dissimilar type, using the entire list.
789 // For example, convert a list of ints to floats, vectors etc.
790 //
791 // \param input the list input values.
792 // \param op the unary conversion operator, which can be used to convert
793 // to other types.
794 //
795 // \code
796 // auto neg = ListOps::create<label>
797 // (
798 // ints,
799 // std::negate<label>()
800 // );
801 //
802 // auto labels = ListOps::create<label>
803 // (
804 // ints,
805 // labelOp<int>()
806 // );
807 //
808 // auto vectors = ListOps::create<vector>
809 // (
810 // ints,
811 // [](const int& val){ return vector(1.5*val, 0, 0); }
812 // );
813 //
814 // \endcode
815 template<class T, class T2, class UnaryOperation>
817 (
818  const UList<T2>& input,
819  const UnaryOperation& op
820 );
821 
822 
823 //- Create a List from an iterator range [first,last) of a dissimilar type.
824 // Uses std::distance for the size.
825 //
826 // \param first the begin of the iterator range
827 // \param last the end of the iterator range
828 // \param op the unary conversion operator, which can be used to convert
829 // to other types.
830 template<class T, class InputIterator, class UnaryOperation>
832 (
833  InputIterator first,
834  InputIterator last,
835  const UnaryOperation& op
836 );
837 
838 
839 //- Create a List filled with default values and various locations with
840 //- another specified value.
841 //
842 // \param len the length of the list
843 // \param locations where to apply the specified value
844 // An out-of-range index is silently ignored.
845 // \param val the value to set at the specified locations
846 // \param deflt the initialization default value
847 template<class T>
849 (
850  const label len,
851  const labelUList& locations,
852  const T& val,
853  const T& deflt = T()
854 );
855 
856 
857 //- Create a List filled with default values and various locations with
858 //- another specified value.
859 //
860 // \param len the length of the list
861 // \param locations where to apply the specified value
862 // An out-of-range index is silently ignored.
863 // \param val the value to set at the specified locations
864 // \param deflt the initialization default value
865 template<class T>
867 (
868  const label len,
869  const labelHashSet& locations,
870  const T& val,
871  const T& deflt = T()
872 );
873 
874 
875 //- Create a List filled with default values and various locations with
876 //- another specified value.
877 //
878 // \param len the length of the list
879 // \param locations where to apply the specified value
880 // An out-of-range index is silently ignored.
881 // \param val the value to set at the specified locations
882 // \param deflt the initialization default value
883 template<class T>
885 (
886  const label len,
887  const UList<bool>& locations,
888  const T& val,
889  const T& deflt = T()
890 );
891 
892 
893 //- Create a List filled with default values and various locations with
894 //- another specified value.
895 //
896 // \param len the length of the list
897 // \param locations where to apply the specified value
898 // An out-of-range index is silently ignored.
899 // \param val the value to set at the specified locations
900 // \param deflt the initialization default value
901 template<class T>
903 (
904  const label len,
905  const bitSet& locations,
906  const T& val,
907  const T& deflt = T()
908 );
909 
910 
911 //- Create a List filled with default values and one specified value,
912 //- which is copy assigned at the specified index
913 //
914 // \param len the length of the list
915 // \param index where to apply the specified value.
916 // An out-of-range index is silently ignored.
917 // \param val the value to copy assign at the specified index
918 // \param deflt the initialization default value
919 template<class T>
921 (
922  const label len,
923  const label index,
924  const T& val,
925  const T& deflt = T()
926 );
927 
928 
929 //- Create a List filled with default values and one specified value,
930 //- which is move assigned at the specified index
931 //
932 // \param len the length of the list
933 // \param index where to apply the specified value.
934 // An out-of-range index is silently ignored.
935 // \param val the value to move assign at the specified index
936 // \param deflt the initialization default value
937 //
938 // For example,
939 // \code
940 // // Gather all unique points on master
941 //
942 // List<pointField> gatheredPoints(Pstream::nProcs());
943 // gatheredPoints[Pstream::myProcNo()] = pointField
944 // (
945 // mesh.points(),
946 // uniqueMeshPoints
947 // );
948 // ...
949 //
950 // // Or else
951 // auto gatheredPoints = ListOps::createWithValue<pointField>
952 // (
953 // Pstream::nProcs(),
954 // Pstream::myProcNo(),
955 // pointField(mesh.points(), uniqueMeshPoints)
956 // );
957 // ...
958 //
959 // \endcode
960 template<class T>
962 (
963  const label len,
964  const label index,
965  T&& val,
966  const T& deflt = T()
967 );
968 
969 } // End namespace ListOps
970 
971 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
972 
973 } // End namespace Foam
974 
975 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
976 
977 #ifdef NoRepository
978  #include "ListOpsTemplates.C"
979 #endif
980 
981 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
982 
983 #endif
984 
985 // ************************************************************************* //
List< T > uniqueSort(const UList< T > &input)
Return sorted list with removal of duplicates.
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
Definition: ListOps.H:827
label findMax(const ListType &input, label start=0)
Linear search for the index of the max element, similar to std::max_element but for lists and returns...
void operator()(labelList &x, const labelList &y) const
Definition: ListOps.C:274
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value...
label count_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Count the number of matching entries.
labelPair findMinMax(const ListType &input, label start=0)
Linear search for the index of the min/max element, similar to std::minmax_element but for lists and ...
labelList findIndices(const ListType &input, const UnaryPredicate &pred, label start=0)
Linear search to find all occurences of given element.
const ListType & values
Definition: ListOps.H:743
bool operator()(const label a, const label b) const
Definition: ListOps.H:770
bool found(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as found_if.
Definition: ListOps.H:858
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
ListType rotateList(const ListType &list, const label n)
Rotate a list by n places.
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values within a list.
labelList duplicateOrder(const UList< T > &input)
Return (sorted) indices corresponding to duplicate list values.
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Binary search to find the index of the last element in a sorted list that is less than value...
Various functors for unary and binary operations. Can be used for parallel combine-reduce operations ...
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
label inplaceMapValue(const labelUList &oldToNew, Container &input)
Map values. Ignore negative values.
greater(const ListType &list)
Definition: ListOps.H:765
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
static bool less(const vector &x, const vector &y)
To compare normals.
const ListType & values
Definition: ListOps.H:763
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
void operator()(List< T > &x, const List< T > &y) const
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
bool found_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
True if there is a value in the list that satisfies the predicate.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
label findMin(const ListType &input, label start=0)
Linear search for the index of the min element, similar to std::min_element but for lists and returns...
scalar y
CompactListList< label > invertOneToManyCompact(const label len, const labelUList &map)
Invert one-to-many compact map. Unmapped elements will be size 0.
Definition: ListOps.C:176
ListType reverseList(const ListType &input)
Reverse a list. First element becomes last element etc.
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
Definition: ListOps.C:126
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
List< T > subsetList(const UList< T > &input, const UnaryPredicate &pred, const bool invert=false)
Copy a subset of the input list when predicate is true.
void identity(labelUList &map, label start=0)
Fill an identity map with (map[i] == i)
Definition: ListOps.H:783
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
void operator()(List< T > &x, const List< T > &y) const
void inplaceUniqueSort(ListType &input)
Inplace sorting and removal of duplicates.
#define FOAM_DEPRECATED_STRICT(since, replacement)
Definition: stdFoam.H:55
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
List< T > create(const UList< T2 > &input, const UnaryOperation &op)
Create a List from a List of a dissimilar type, using the entire list.
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:51
void inplaceMapKey(const labelUList &oldToNew, Container &input)
Rewrite with mapped keys. Ignore elements with negative key.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
labelList uniqueOrder(const UList< T > &input)
Return (sorted) indices corresponding to unique list values.
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:30
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values within a list.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
void inplaceRotateList(ListType< DataType > &list, label n)
Inplace reversal of a list using the Reversal Block Swapping algorithm.
label find_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
label n
bool operator()(const label a, const label b) const
Definition: ListOps.H:750
List< T > createWithValue(const label len, const labelUList &locations, const T &val, const T &deflt=T())
Create a List filled with default values and various locations with another specified value...
label findIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Deprecated(2017-10) search for first occurrence of the given element.
Definition: ListOps.H:517
List< label > labelList
A List of labels.
Definition: List.H:62
void setValue(UList< T > &list, const labelUList &locations, const T &val)
Set various locations of the list with a specified value.
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
void inplaceReverseList(ListType &input)
Inplace reversal of a list using Swap.
Map< label > invertToMap(const labelUList &values)
Create inverse mapping, which is a lookup table into the given list.
Definition: ListOps.C:107
less(const ListType &list)
Definition: ListOps.H:745
Namespace for OpenFOAM.