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