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