31template<
class IntListType>
35 const IntListType& input
38 const label len = input.size();
40 IntListType output(len);
43 for (label i=0; i < len; ++i)
47 output[i] = oldToNew[input[i]];
55template<
class IntListType>
58 const labelUList& oldToNew,
62 const label len = input.size();
64 for (label i=0; i < len; ++i)
68 input[i] = oldToNew[input[i]];
74template<
class IntListType>
77 const Map<label>& oldToNew,
81 const label len = input.size();
83 for (label i = 0; i < len; ++i)
85 const auto fnd = oldToNew.cfind(input[i]);
95template<
class ListType>
98 const labelUList& oldToNew,
99 const ListType& input,
103 const label len = input.size();
105 ListType output(len);
109 for (label i=0; i < len; ++i)
111 const label newIdx = oldToNew[i];
117 output[newIdx] = input[i];
126 output[i] = input[i];
132 output.resize(maxIdx+1);
139template<
class ListType>
142 const labelUList& oldToNew,
143 ListType& inputOutput,
153 const ListType& input = inputOutput;
154 const label len = input.size();
156 ListType output(len);
160 for (label i=0; i < len; ++i)
162 const label newIdx = oldToNew[i];
168 output[newIdx] = input[i];
177 output[i] = input[i];
183 output.resize(maxIdx+1);
186 inputOutput.transfer(output);
190template<
unsigned W
idth>
193 const labelUList& oldToNew,
194 const PackedList<Width>& input,
198 const label len = input.
size();
200 PackedList<Width> output(len);
203 for (label i=0; i < len; ++i)
205 const auto& val = input.get(i);
207 const label newIdx = oldToNew[i];
214 output.set(newIdx, val);
229 output.resize(maxIdx+1);
240template<
unsigned W
idth>
243 const labelUList& oldToNew,
244 PackedList<Width>& input,
255template<
class Container>
258 const labelUList& oldToNew,
262 Container output(input.capacity());
264 for (
auto iter = input.begin(); iter != input.end(); ++iter)
266 const label oldIdx = iter.key();
272 output.insert(oldToNew[oldIdx], iter.val());
276 input.transfer(output);
280template<
class Container>
283 const labelUList& oldToNew,
289 for (
auto iter = input.begin(); iter != input.end(); ++iter)
291 const label oldIdx = iter.val();
297 const label newIdx = oldToNew[oldIdx];
299 if (oldIdx != newIdx)
311template<
class Container>
314 const Map<label>& mapper,
325 for (
auto iter = input.begin(); iter != input.end(); ++iter)
327 label& value = iter.val();
329 auto mapIter = mapper.find(value);
330 if (mapIter.good() && value != mapIter.val())
332 value = mapIter.val();
344 const UList<T>& input
356 const UList<T>& input,
364template<
class T,
class ListComparePredicate>
367 const UList<T>& input,
369 const ListComparePredicate& comp
372 if (input.size() < 2)
380 const label last = (order.size()-1);
382 for (label i = 0; i < last; ++i)
384 if (input[order[i]] == input[order[i+1]])
386 order[
count] = order[i];
397 const UList<T>& input
409 const UList<T>& input,
417template<
class T,
class ListComparePredicate>
420 const UList<T>& input,
422 const ListComparePredicate& comp
427 if (order.size() > 1)
429 const label last = (order.size()-1);
431 for (label i = 0; i < last; ++i)
433 if (input[order[i]] != input[order[i+1]])
435 order[count++] = order[i];
438 order[
count++] = order[last];
447 List<T> output(input);
449 const label len = output.size();
456 for (label i = 1; i < len; ++i)
458 if (output[count] != output[i])
460 output[++
count] = output[i];
464 output.resize(count+1);
471template<
class ListType>
482template<
class ListType,
class ListComparePredicate>
486 const ListComparePredicate& comp
490 uniqueOrder(input, order, comp);
492 const label len = order.size();
494 ListType output(len);
497 for (label i=0; i < len; ++i)
499 output[i] = std::move(input[order[i]]);
502 input.transfer(output);
506template<
class BoolListType,
class T>
509 const BoolListType& select,
510 const UList<T>& input,
516 const label len = input.
size();
522 for (label i=0; i < len; ++i)
524 if (select[i] ? !invert : invert)
526 output[
count] = input[i];
531 output.resize(count);
540 const bitSet& select,
541 const UList<T>& input,
545 const label len = input.
size();
553 output.resize(
select.count());
555 for (
const label i : select)
559 output[
count] = input[i];
566 output.resize(outlen);
568 for (label i=0; i < len; ++i)
572 output[
count] = input[i];
574 if (count >= outlen)
break;
579 output.resize(count);
585template<
class BoolListType,
class ListType>
588 const BoolListType& select,
595 const label len = input.size();
599 for (label i=0; i < len; ++i)
601 if (select[i] ? !invert : invert)
605 input[count] = std::move(input[i]);
615template<
class ListType>
618 const bitSet& select,
629 const label len = input.size();
631 for (
const label i :
select)
637 input[
count] = std::move(input[i]);
650 for (label i=0; i < len; ++i)
656 input[
count] = std::move(input[i]);
659 if (count >= outlen)
break;
668template<
class T,
class UnaryPredicate>
671 const UList<T>& input,
672 const UnaryPredicate& pred,
676 const label len = input.
size();
681 for (label i=0; i < len; ++i)
683 if (pred(input[i]) ? !invert : invert)
685 output[
count] = input[i];
690 output.resize(count);
696template<
class ListType,
class UnaryPredicate>
700 const UnaryPredicate& pred,
704 const label len = input.size();
707 for (label i=0; i < len; ++i)
709 if (pred(input[i]) ? !invert : invert)
713 input[count] = std::move(input[i]);
722template<
class InputIntListType,
class OutputIntListType>
726 const UList<InputIntListType>& input,
727 List<OutputIntListType>& output
733 for (
const InputIntListType& sublist : input)
737 sizes[sublist[idx]]++;
745 output[outi].resize(sizes[outi]);
752 const InputIntListType& sublist = input[listi];
756 const label outi = sublist[idx];
758 output[outi][sizes[outi]++] = listi;
764template<
class ListType>
767 const ListType& input,
768 typename ListType::const_reference val,
772 const label len = input.
size();
779 for (label i = start; i < len; ++i)
783 if (!count) start = i;
794 const label total =
count;
796 for (label i = start; i < len; ++i)
801 if (++count == total)
813template<
class ListType>
816 const ListType& input,
820 const label len = input.size();
822 if (start < 0 || start >= len)
827 for (label i = start+1; i < len; ++i)
829 if (input[i] < input[start])
839template<
class ListType>
842 const ListType& input,
846 const label len = input.size();
848 if (start < 0 || start >= len)
853 for (label i = start+1; i < len; ++i)
855 if (input[start] < input[i])
865template<
class ListType>
868 const ListType& input,
872 const label len = input.
size();
874 if (start < 0 || start >= len)
879 label minIdx = start;
880 label maxIdx = start;
882 for (label i = start+1; i < len; ++i)
884 if (input[i] < input[minIdx])
888 if (input[maxIdx] < input[i])
898template<
class ListType>
901 const ListType& input,
902 typename ListType::const_reference val,
907 label high = input.size() - 1;
909 if (start < 0 || start >= input.size())
916 const label mid = (low + high)/2;
918 if (val < input[mid])
922 else if (input[mid] < val)
936template<
class ListType,
class T,
class ComparePredicate>
939 const ListType& input,
942 const ComparePredicate& comp
946 label high = input.size() - 1;
948 if (start < 0 || start >= input.size())
953 while ((high - low) > 1)
955 const label mid = (low + high)/2;
957 if (comp(input[mid], val))
967 if (comp(input[high], val))
971 else if (comp(input[low], val))
982template<
class ListType,
class T>
985 const ListType& input,
1000template<
class ListType>
1003 const label len = input.size();
1004 const label last = (len - 1);
1006 ListType output(len);
1009 for (label i=0; i < len; ++i)
1011 output[i] = input[last - i];
1018template<
class ListType>
1021 const label len = input.size();
1022 const label last = (len - 1);
1023 const label n2 = len >> 1;
1025 for (label i=0; i<n2; ++i)
1032template<
class ListType>
1035 const label len = input.size();
1037 ListType output(len);
1040 for (label i=0; i<len; ++i)
1042 label index = (i -
n) % len;
1049 output[i] = input[index];
1056template<
template<
typename>
class ListType,
class DataType>
1059 const label len = input.size();
1061 n = (len -
n) % len;
1068 SubList<DataType> firstHalf(input,
n, 0);
1069 SubList<DataType> secondHalf(input, len -
n,
n);
1112 for (
const T& val :
y)
1126template<
class Type1,
class Type2>
1129 const UList<Type1>& a,
1130 const UList<Type2>&
b
1135 (a.size() ==
b.size())
1136 && std::equal(a.cbegin(), a.cend(),
b.cbegin())
1141template<
class Type1,
class Type2,
class BinaryPredicate>
1146 BinaryPredicate pred
1151 (a.
size() ==
b.size())
1152 && std::equal(a.
cbegin(), a.
cend(),
b.cbegin(), pred)
1157template<
class ListType>
1160 const ListType& input,
1161 typename ListType::const_reference val,
1167 const label len = input.size();
1171 for (label i = start; i < len; ++i)
1173 if (val == input[i])
1184template<
class ListType,
class UnaryPredicate>
1187 const ListType& input,
1188 const UnaryPredicate& pred,
1194 const label len = input.size();
1198 for (label i = start; i < len; ++i)
1211template<
class ListType,
class UnaryPredicate>
1214 const ListType& input,
1215 const UnaryPredicate& pred,
1219 const label len = input.size();
1223 for (label i = start; i < len; ++i)
1236template<
class ListType,
class UnaryPredicate>
1239 const ListType& input,
1240 const UnaryPredicate& pred,
1244 return (ListOps::find_if(input, pred, start) >= 0);
1248template<
class ListType,
class UnaryPredicate>
1251 const ListType& input,
1252 const UnaryPredicate& pred,
1256 const label len = input.
size();
1263 for (label i = start; i < len; ++i)
1267 if (!count) start = i;
1278 const label total =
count;
1280 for (label i = start; i < len; ++i)
1285 if (++count == total)
1301 const labelUList& locations,
1305 const label len = list.size();
1307 for (
const label index : locations)
1310 if (index >= 0 && index < len)
1322 const labelHashSet& locations,
1326 const label len = list.size();
1328 for (
const label index : locations)
1331 if (index >= 0 && index < len)
1343 const UList<bool>& locations,
1347 const label
end =
Foam::min(list.size(), locations.size());
1350 for (label index = 0; index <
end; ++index)
1352 if (locations[index])
1364 const bitSet& locations,
1368 const label len = list.size();
1372 label
pos = locations.find_first();
1374 pos = locations.find_next(
pos)
1382template<
class T,
class T2,
class UnaryOperation>
1385 const UList<T2>& input,
1386 const UnaryOperation& op
1389 const label len = input.
size();
1391 List<T> output(len);
1395 const T2* in = input.begin();
1396 T* out = output.begin();
1398 for (label i = 0; i < len; ++i)
1407template<
class T,
class InputIterator,
class UnaryOperation>
1410 InputIterator first,
1412 const UnaryOperation& op
1415 const label len = std::distance(first, last);
1417 List<T> output(len);
1421 T* out = output.begin();
1423 while (first != last)
1438 const labelUList& locations,
1443 List<T> list(len, deflt);
1444 ListOps::setValue(list, locations, val);
1454 const labelHashSet& locations,
1459 List<T> list(len, deflt);
1460 ListOps::setValue(list, locations, val);
1470 const UList<bool>& locations,
1475 List<T> list(len, deflt);
1476 ListOps::setValue(list, locations, val);
1486 const bitSet& locations,
1491 List<T> list(len, deflt);
1492 ListOps::setValue(list, locations, val);
1507 List<T> list(len, deflt);
1510 if (index >= 0 && index < len)
1528 List<T> list(len, deflt);
1531 if (index >= 0 && index < len)
1533 list[index] = std::move(val);
static constexpr label size() noexcept
Return the number of elements in the FixedList.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize(const label len)
Adjust allocated size of list.
void clear()
Clear the list, i.e. set size to zero.
A HashTable to objects of type <T> with a label key.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
label size() const noexcept
Number of entries.
A non-owning sub-view of a List (allocated or unallocated storage).
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant UList.
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
void size(const label n)
Older name for setAddressableSize.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
label find_next(label pos) const
Locate the next bit set, starting one beyond the specified position.
label find_first() const
Locate the first bit that is set.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
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.
label find_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
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.
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.
dimensionedScalar pos(const dimensionedScalar &ds)
Pair< label > labelPair
A pair of labels.
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values within a list.
List< label > labelList
A List of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
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 Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Exchange contents of lists - see DynamicList::swap().
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.
void inplaceMapKey(const labelUList &oldToNew, Container &input)
Rewrite with mapped keys. Ignore elements with negative key.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
void inplaceUniqueSort(ListType &input)
Inplace sorting and removal of duplicates.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
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.
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.
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.
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.
void stableSort(UList< T > &list)
Stable sort the list.
#define forAll(list, i)
Loop across all elements in list.
List helper to append y elements onto the end of x.
List helper to append y unique elements onto the end of x.
A list compare binary predicate for normal sort.