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,
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 //- Linear search to find all occurences of given element.
659 template<class ListType, class UnaryPredicate>
661 (
662  const ListType& input,
663  const UnaryPredicate& pred,
664  label start=0
665 );
666 
667 
668 //- Set various locations of the list with a specified value.
669 //
670 // \param list the list to modify
671 // \param locations where to apply the specified value
672 // An out-of-range index is silently ignored.
673 // \param val the value to set at the specified locations
674 template<class T>
675 void setValue
676 (
677  UList<T>& list,
678  const labelUList& locations,
679  const T& val
680 );
681 
682 
683 //- Set various locations of the list with a specified value.
684 //
685 // \param list the list to modify
686 // \param locations where to apply the specified value
687 // An out-of-range index is silently ignored.
688 // \param val the value to set at the specified locations
689 template<class T>
690 void setValue
691 (
692  UList<T>& list,
693  const labelHashSet& locations,
694  const T& val
695 );
696 
697 
698 //- Set various locations of the list with a specified value.
699 //
700 // \param list the list to modify
701 // \param locations where to apply the specified value
702 // An out-of-range index is silently ignored.
703 // \param val the value to set at the specified locations
704 template<class T>
705 void setValue
706 (
707  UList<T>& list,
708  const UList<bool>& locations,
709  const T& val
710 );
711 
712 
713 //- Set various locations of the list with a specified value.
714 //
715 // \param list the list to modify
716 // \param locations where to apply the specified value
717 // An out-of-range index is silently ignored.
718 // \param val the value to set at the specified locations
719 template<class T>
720 void setValue
721 (
722  UList<T>& list,
723  const bitSet& locations,
724  const T& val
725 );
726 
727 
728 //- Create a List from a List of a dissimilar type, using the entire list.
729 // For example, convert a list of ints to floats, vectors etc.
730 //
731 // \param input the list input values.
732 // \param op the unary conversion operator, which can be used to convert
733 // to other types.
734 //
735 // \code
736 // auto neg = ListOps::create<label>
737 // (
738 // ints,
739 // std::negate<label>()
740 // );
741 //
742 // auto labels = ListOps::create<label>
743 // (
744 // ints,
745 // labelOp<int>()
746 // );
747 //
748 // auto vectors = ListOps::create<vector>
749 // (
750 // ints,
751 // [](const int& val){ return vector(1.5*val, 0, 0); }
752 // );
753 //
754 // \endcode
755 template<class T, class T2, class UnaryOperation>
757 (
758  const UList<T2>& input,
759  const UnaryOperation& op
760 );
761 
762 
763 //- Create a List from an iterator range [first,last) of a dissimilar type.
764 // Uses std::distance for the size.
765 //
766 // \param first the begin of the iterator range
767 // \param last the end of the iterator range
768 // \param op the unary conversion operator, which can be used to convert
769 // to other types.
770 template<class T, class InputIterator, class UnaryOperation>
772 (
773  InputIterator first,
774  InputIterator last,
775  const UnaryOperation& op
776 );
777 
778 
779 //- Create a List filled with default values and various locations with
780 //- another specified value.
781 //
782 // \param len the length of the list
783 // \param locations where to apply the specified value
784 // An out-of-range index is silently ignored.
785 // \param val the value to set at the specified locations
786 // \param deflt the initialization default value
787 template<class T>
789 (
790  const label len,
791  const labelUList& locations,
792  const T& val,
793  const T& deflt = T()
794 );
795 
796 
797 //- Create a List filled with default values and various locations with
798 //- another specified value.
799 //
800 // \param len the length of the list
801 // \param locations where to apply the specified value
802 // An out-of-range index is silently ignored.
803 // \param val the value to set at the specified locations
804 // \param deflt the initialization default value
805 template<class T>
807 (
808  const label len,
809  const labelHashSet& locations,
810  const T& val,
811  const T& deflt = T()
812 );
813 
814 
815 //- Create a List filled with default values and various locations with
816 //- another specified value.
817 //
818 // \param len the length of the list
819 // \param locations where to apply the specified value
820 // An out-of-range index is silently ignored.
821 // \param val the value to set at the specified locations
822 // \param deflt the initialization default value
823 template<class T>
825 (
826  const label len,
827  const UList<bool>& locations,
828  const T& val,
829  const T& deflt = T()
830 );
831 
832 
833 //- Create a List filled with default values and various locations with
834 //- another specified value.
835 //
836 // \param len the length of the list
837 // \param locations where to apply the specified value
838 // An out-of-range index is silently ignored.
839 // \param val the value to set at the specified locations
840 // \param deflt the initialization default value
841 template<class T>
843 (
844  const label len,
845  const bitSet& locations,
846  const T& val,
847  const T& deflt = T()
848 );
849 
850 
851 //- Create a List filled with default values and one specified value,
852 //- which is copy assigned at the specified index
853 //
854 // \param len the length of the list
855 // \param index where to apply the specified value.
856 // An out-of-range index is silently ignored.
857 // \param val the value to copy assign at the specified index
858 // \param deflt the initialization default value
859 template<class T>
861 (
862  const label len,
863  const label index,
864  const T& val,
865  const T& deflt = T()
866 );
867 
868 
869 //- Create a List filled with default values and one specified value,
870 //- which is move assigned at the specified index
871 //
872 // \param len the length of the list
873 // \param index where to apply the specified value.
874 // An out-of-range index is silently ignored.
875 // \param val the value to move assign at the specified index
876 // \param deflt the initialization default value
877 //
878 // For example,
879 // \code
880 // // Gather all unique points on master
881 //
882 // List<pointField> gatheredPoints(Pstream::nProcs());
883 // gatheredPoints[Pstream::myProcNo()] = pointField
884 // (
885 // mesh.points(),
886 // uniqueMeshPoints
887 // );
888 // ...
889 //
890 // // Or else
891 // auto gatheredPoints = ListOps::createWithValue<pointField>
892 // (
893 // Pstream::nProcs(),
894 // Pstream::myProcNo(),
895 // pointField(mesh.points(), uniqueMeshPoints)
896 // );
897 // ...
898 //
899 // \endcode
900 template<class T>
902 (
903  const label len,
904  const label index,
905  T&& val,
906  const T& deflt = T()
907 );
908 
909 } // End namespace ListOps
910 
911 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
912 
913 } // End namespace Foam
914 
915 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
916 
917 #ifdef NoRepository
918  #include "ListOpsTemplates.C"
919 #endif
920 
921 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
922 
923 #endif
924 
925 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
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:694
Foam::inplaceReverseList
void inplaceReverseList(ListType &input)
Inplace reversal of a list using Swap.
Definition: ListOpsTemplates.C:1015
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:63
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:1078
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:1053
Foam::inplaceUniqueSort
void inplaceUniqueSort(ListType &input)
Inplace sorting and removal of duplicates.
Definition: ListOpsTemplates.C:468
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:720
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::ListOps::findIndices
labelList findIndices(const ListType &input, const UnaryPredicate &pred, label start=0)
Linear search to find all occurences of given element.
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:1104
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:1029
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:583
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:997
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:1217
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: BitOps.H:63
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
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
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:1156
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:85
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.