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-2019 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 occurence 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 label FOAM_DEPRECATED(2017-10) findIndex
405 (
406  const ListType& input,
407  typename ListType::const_reference val,
408  const label start=0
409 )
410 {
411  return input.find(val, start);
412 }
413 
414 
415 //- Linear search to find all occurences of given element.
416 template<class ListType>
417 labelList findIndices
418 (
419  const ListType& input,
420  typename ListType::const_reference val,
421  label start=0
422 );
423 
424 
425 //- Linear search for the index of the min element,
426 //- similar to std::min_element but for lists and returns the index.
427 //
428 // \tparam ListType The input list type
429 //
430 // \param input The list to search
431 // \param start The start index in the list (default: 0)
432 //
433 // \return The min index or -1 on error.
434 template<class ListType>
435 label findMin(const ListType& input, label start=0);
436 
437 //- Linear search for the index of the max element,
438 //- similar to std::max_element but for lists and returns the index.
439 //
440 // \tparam ListType The input list type
441 //
442 // \param input The list to search
443 // \param start The start index in the list (default: 0)
444 //
445 // \return The max index or -1 on error.
446 template<class ListType>
447 label findMax(const ListType& input, label start=0);
448 
449 
450 //- Linear search for the index of the min/max element,
451 //- similar to std::minmax_element but for lists and returns the index.
452 //
453 // \tparam ListType The input list type
454 //
455 // \param input The list to search
456 // \param start The start index in the list (default: 0)
457 //
458 // \return The min/max indices as a Pair (min is first max is second)
459 // or (-1,-1) on error.
460 template<class ListType>
461 labelPair findMinMax(const ListType& input, label start=0);
462 
463 
464 //- Binary search to find the index of the last element in a sorted list
465 //- that is less than value.
466 //
467 // Uses the global <code> < </code> operator and thus
468 // <code> (list[i] < val) </code> for the test.
469 //
470 // \tparam ListType The input list type
471 // \tparam T The value type (should normally be ListType::value_type)
472 //
473 // \param input The sorted list to search
474 // \param val The value for searching/comparing
475 // \param start The start index in the list (default: 0)
476 //
477 // \return The index found or -1 if not found.
478 template<class ListType>
480 (
481  const ListType& input,
482  typename ListType::const_reference val,
483  const label start=0
484 );
485 
486 
487 //- Binary search to find the index of the last element in a sorted list
488 //- that is less than value.
489 //
490 // Uses <code> lessOp<T>() </code> and thus
491 // <code> lessOp<T>(list[i], val) </code> for the test.
492 //
493 // \tparam ListType The input list type
494 // \tparam T The value type (is often the same as ListType::value_type)
495 // \tparam ComparePredicate The type of the comparison functor that
496 // returns true for sorting below.
497 //
498 // \param input The sorted list to search
499 // \param val The value for searching/comparing
500 // \param start The start index in the list
501 // \param comp The comparison functor for testing.
502 // Uses <code> comp(list[i], val) </code> for the test.
503 //
504 // \return The index found or -1 if not found.
505 template<class ListType, class T, class ComparePredicate>
507 (
508  const ListType& input,
509  const T& val,
510  const label start,
511  const ComparePredicate& comp
512 );
513 
514 
515 //- Binary search to find the index of the last element in a sorted list
516 //- that is less than value.
517 //
518 // Uses <code> lessOp<T>() </code> and thus
519 // <code> lessOp<T>(list[i], val) </code> for the test.
520 //
521 // \tparam ListType The input list type
522 // \tparam T The value type (should normally be ListType::value_type)
523 //
524 // \param input The sorted list to search
525 // \param val The value for searching/comparing
526 // \param start The start index in the list (default: 0)
527 //
528 // \return The index found or -1 if not found.
529 template<class ListType, class T>
531 (
532  const ListType& input,
533  const T& val,
534  const label start=0
535 );
536 
537 
538 //- Reverse a list. First element becomes last element etc.
539 template<class ListType>
540 ListType reverseList(const ListType& input);
541 
542 
543 //- Inplace reversal of a list using Swap.
544 template<class ListType>
545 void inplaceReverseList(ListType& input);
546 
547 
548 //- Rotate a list by n places.
549 // If n is positive rotate clockwise/right/down.
550 // If n is negative rotate anti-clockwise/left/up.
551 template<class ListType>
552 ListType rotateList(const ListType& list, const label n);
553 
554 
555 //- Inplace reversal of a list using the Reversal Block Swapping algorithm.
556 template<template<typename> class ListType, class DataType>
557 void inplaceRotateList(ListType<DataType>& list, label n);
558 
559 
560 /*---------------------------------------------------------------------------*\
561  Namespace ListOps Declaration
562 \*---------------------------------------------------------------------------*/
563 
564 namespace ListOps
565 {
566 
567 //- List helper to append y elements onto the end of x
568 template<class T>
570 {
571  void operator()(List<T>& x, const List<T>& y) const;
572 };
573 
574 //- List helper to append y unique elements onto the end of x
575 template<class T>
577 {
578  void operator()(List<T>& x, const List<T>& y) const;
579 };
580 
581 
582 // Public classes
583 
584 //- A list compare binary predicate for normal sort
585 template<class ListType>
586 struct less
587 {
588  const ListType& values;
589 
590  less(const ListType& list)
591  :
592  values(list)
593  {}
594 
595  bool operator()(const label a, const label b) const
596  {
597  return values[a] < values[b];
598  }
599 };
600 
601 
602 //- A list compare binary predicate for reverse sort
603 template<class ListType>
604 struct greater
605 {
606  const ListType& values;
607 
608  greater(const ListType& list)
609  :
610  values(list)
611  {}
612 
613  bool operator()(const label a, const label b) const
614  {
615  return values[b] < values[a];
616  }
617 };
618 
619 
620 //- Set identity map with (map[i] == i)
621 // Optionally with an alternative start index, so that (map[i] == i+start)
622 void identity(labelUList& map, label start=0);
623 
624 
625 //- Find index of the first occurrence that satisfies the predicate.
626 // When start is specified, any occurrences before start are ignored.
627 // Linear search.
628 // \return position in list or -1 if not found.
629 template<class ListType, class UnaryPredicate>
630 label find
631 (
632  const ListType& input,
633  const UnaryPredicate& pred,
634  const label start=0
635 );
636 
637 
638 //- True if there is a value in the list that satisfies the predicate.
639 // When start is specified, any occurences before start are ignored.
640 // Linear search.
641 // \return true if found.
642 template<class ListType, class UnaryPredicate>
643 bool found
644 (
645  const ListType& input,
646  const UnaryPredicate& pred,
647  const label start=0
648 );
649 
650 
651 //- Set various locations of the list with a specified value.
652 //
653 // \param list the list to modify
654 // \param locations where to apply the specified value
655 // An out-of-range index is silently ignored.
656 // \param val the value to set at the specified locations
657 template<class T>
658 void setValue
659 (
660  UList<T>& list,
661  const labelUList& locations,
662  const T& val
663 );
664 
665 
666 //- Set various locations of the list with a specified value.
667 //
668 // \param list the list to modify
669 // \param locations where to apply the specified value
670 // An out-of-range index is silently ignored.
671 // \param val the value to set at the specified locations
672 template<class T>
673 void setValue
674 (
675  UList<T>& list,
676  const labelHashSet& locations,
677  const T& val
678 );
679 
680 
681 //- Set various locations of the list with a specified value.
682 //
683 // \param list the list to modify
684 // \param locations where to apply the specified value
685 // An out-of-range index is silently ignored.
686 // \param val the value to set at the specified locations
687 template<class T>
688 void setValue
689 (
690  UList<T>& list,
691  const UList<bool>& locations,
692  const T& val
693 );
694 
695 
696 //- Set various locations of the list with a specified value.
697 //
698 // \param list the list to modify
699 // \param locations where to apply the specified value
700 // An out-of-range index is silently ignored.
701 // \param val the value to set at the specified locations
702 template<class T>
703 void setValue
704 (
705  UList<T>& list,
706  const bitSet& locations,
707  const T& val
708 );
709 
710 
711 //- Create a List from a List of a dissimilar type, using the entire list.
712 // For example, convert a list of ints to floats, vectors etc.
713 //
714 // \param input the list input values.
715 // \param op the unary conversion operator, which can be used to convert
716 // to other types.
717 //
718 // \code
719 // auto neg = ListOps::create<label>
720 // (
721 // ints,
722 // std::negate<label>()
723 // );
724 //
725 // auto labels = ListOps::create<label>
726 // (
727 // ints,
728 // labelOp<int>()
729 // );
730 //
731 // auto vectors = ListOps::create<vector>
732 // (
733 // ints,
734 // [](const int& val){ return vector(1.5*val, 0, 0); }
735 // );
736 //
737 // \endcode
738 template<class T, class T2, class UnaryOperation>
740 (
741  const UList<T2>& input,
742  const UnaryOperation& op
743 );
744 
745 
746 //- Create a List from an iterator range [first,last) of a dissimilar type.
747 // Uses std::distance for the size.
748 //
749 // \param first the begin of the iterator range
750 // \param last the end of the iterator range
751 // \param op the unary conversion operator, which can be used to convert
752 // to other types.
753 template<class T, class InputIterator, class UnaryOperation>
755 (
756  InputIterator first,
757  InputIterator last,
758  const UnaryOperation& op
759 );
760 
761 
762 //- Create a List filled with default values and various locations with
763 //- another specified value.
764 //
765 // \param len the length of the list
766 // \param locations where to apply the specified value
767 // An out-of-range index is silently ignored.
768 // \param val the value to set at the specified locations
769 // \param deflt the initialization default value
770 template<class T>
772 (
773  const label len,
774  const labelUList& locations,
775  const T& val,
776  const T& deflt = T()
777 );
778 
779 
780 //- Create a List filled with default values and various locations with
781 //- another specified value.
782 //
783 // \param len the length of the list
784 // \param locations where to apply the specified value
785 // An out-of-range index is silently ignored.
786 // \param val the value to set at the specified locations
787 // \param deflt the initialization default value
788 template<class T>
790 (
791  const label len,
792  const labelHashSet& locations,
793  const T& val,
794  const T& deflt = T()
795 );
796 
797 
798 //- Create a List filled with default values and various locations with
799 //- another specified value.
800 //
801 // \param len the length of the list
802 // \param locations where to apply the specified value
803 // An out-of-range index is silently ignored.
804 // \param val the value to set at the specified locations
805 // \param deflt the initialization default value
806 template<class T>
808 (
809  const label len,
810  const UList<bool>& locations,
811  const T& val,
812  const T& deflt = T()
813 );
814 
815 
816 //- Create a List filled with default values and various locations with
817 //- another specified value.
818 //
819 // \param len the length of the list
820 // \param locations where to apply the specified value
821 // An out-of-range index is silently ignored.
822 // \param val the value to set at the specified locations
823 // \param deflt the initialization default value
824 template<class T>
826 (
827  const label len,
828  const bitSet& locations,
829  const T& val,
830  const T& deflt = T()
831 );
832 
833 
834 //- Create a List filled with default values and one specified value,
835 //- which is copy assigned at the specified index
836 //
837 // \param len the length of the list
838 // \param index where to apply the specified value.
839 // An out-of-range index is silently ignored.
840 // \param val the value to copy assign at the specified index
841 // \param deflt the initialization default value
842 template<class T>
844 (
845  const label len,
846  const label index,
847  const T& val,
848  const T& deflt = T()
849 );
850 
851 
852 //- Create a List filled with default values and one specified value,
853 //- which is move assigned at the specified index
854 //
855 // \param len the length of the list
856 // \param index where to apply the specified value.
857 // An out-of-range index is silently ignored.
858 // \param val the value to move assign at the specified index
859 // \param deflt the initialization default value
860 //
861 // For example,
862 // \code
863 // // Gather all unique points on master
864 //
865 // List<pointField> gatheredPoints(Pstream::nProcs());
866 // gatheredPoints[Pstream::myProcNo()] = pointField
867 // (
868 // mesh.points(),
869 // uniqueMeshPoints
870 // );
871 // ...
872 //
873 // // Or else
874 // auto gatheredPoints = ListOps::createWithValue<pointField>
875 // (
876 // Pstream::nProcs(),
877 // Pstream::myProcNo(),
878 // pointField(mesh.points(), uniqueMeshPoints)
879 // );
880 // ...
881 //
882 // \endcode
883 template<class T>
885 (
886  const label len,
887  const label index,
888  T&& val,
889  const T& deflt = T()
890 );
891 
892 } // End namespace ListOps
893 
894 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
895 
896 } // End namespace Foam
897 
898 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
899 
900 #ifdef NoRepository
901  #include "ListOpsTemplates.C"
902 #endif
903 
904 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
905 
906 #endif
907 
908 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
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:595
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:608
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:590
Foam::invert
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:35
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:604
Foam::ListOps::less
A list compare binary predicate for normal sort.
Definition: ListOps.H:586
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::FOAM_DEPRECATED
label FOAM_DEPRECATED(2017-10) findIndex(const ListType &input
Deprecated(2017-10) search for first occurence of the given element.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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::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:588
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:613
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:576
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:569
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:202
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
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:606
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::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:79
Foam::invertOneToMany
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
Definition: ListOps.C:113
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.