31 template<
class IntListType>
35 const IntListType&
input 38 const label len =
input.size();
43 for (label i=0; i < len; ++i)
55 template<
class IntListType>
62 const label len =
input.size();
64 for (label i=0; i < len; ++i)
74 template<
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]);
95 template<
class ListType>
99 const ListType&
input,
103 const label len =
input.size();
109 for (label i=0; i < len; ++i)
111 const label newIdx = oldToNew[i];
139 template<
class ListType>
143 ListType& inputOutput,
153 const ListType&
input = inputOutput;
154 const label len =
input.size();
160 for (label i=0; i < len; ++i)
162 const label newIdx = oldToNew[i];
186 inputOutput.transfer(
output);
190 template<
unsigned W
idth>
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];
240 template<
unsigned W
idth>
244 PackedList<Width>&
input,
255 template<
class Container>
264 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
266 const label oldIdx = iter.key();
272 output.insert(oldToNew[oldIdx], iter.val());
280 template<
class Container>
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)
311 template<
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,
364 template<
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)
386 order[
count] = order[i];
397 const UList<T>&
input 409 const UList<T>&
input,
417 template<
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)
435 order[
count++] = order[i];
438 order[
count++] = order[last];
449 const label len =
output.size();
456 for (label i = 1; i < len; ++i)
471 template<
class ListType>
482 template<
class ListType,
class ListComparePredicate>
486 const ListComparePredicate& comp
492 const label len = order.size();
497 for (label i=0; i < len; ++i)
506 template<
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)
541 const UList<T>&
input,
545 const label len =
input.size();
555 for (
const label i :
select)
568 for (label i=0; i < len; ++i)
574 if (
count >= outlen)
break;
585 template<
class BoolListType,
class ListType>
588 const BoolListType&
select,
595 const label len =
input.size();
599 for (label i=0; i < len; ++i)
615 template<
class ListType>
629 const label len =
input.size();
631 for (
const label i :
select)
650 for (label i=0; i < len; ++i)
659 if (
count >= outlen)
break;
668 template<
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)
696 template<
class ListType,
class UnaryPredicate>
700 const UnaryPredicate& pred,
704 const label len =
input.size();
707 for (label i=0; i < len; ++i)
722 template<
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;
764 template<
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)
813 template<
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)
839 template<
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)
865 template<
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)
898 template<
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)
936 template<
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))
982 template<
class ListType,
class T>
985 const ListType&
input,
1000 template<
class ListType>
1003 const label len =
input.size();
1004 const label last = (len - 1);
1009 for (label i=0; i < len; ++i)
1018 template<
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)
1032 template<
class ListType>
1035 const label len =
input.size();
1040 for (label i=0; i<len; ++i)
1042 label index = (i -
n) % len;
1056 template<
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)
1125 template<
class ListType,
class UnaryPredicate>
1128 const ListType&
input,
1129 const UnaryPredicate& pred,
1135 const label len =
input.size();
1139 for (label i = start; i < len; ++i)
1152 template<
class ListType,
class UnaryPredicate>
1155 const ListType&
input,
1156 const UnaryPredicate& pred,
1160 const label len =
input.size();
1164 for (label i = start; i < len; ++i)
1177 template<
class ListType,
class UnaryPredicate>
1180 const ListType&
input,
1181 const UnaryPredicate& pred,
1189 template<
class ListType,
class UnaryPredicate>
1192 const ListType&
input,
1193 const UnaryPredicate& pred,
1197 const label len =
input.size();
1204 for (label i = start; i < len; ++i)
1208 if (!
count) start = i;
1219 const label total =
count;
1221 for (label i = start; i < len; ++i)
1226 if (++
count == total)
1246 const label len = list.
size();
1248 for (
const label index : locations)
1251 if (index >= 0 && index < len)
1267 const label len = list.size();
1269 for (
const label index : locations)
1272 if (index >= 0 && index < len)
1284 const UList<bool>& locations,
1288 const label len = list.size();
1289 const label
count = locations.size();
1293 for (label index = 0; index <
end; ++index)
1295 if (locations[index])
1307 const bitSet& locations,
1311 const label len = list.size();
1315 label
pos = locations.find_first();
1317 pos = locations.find_next(
pos)
1325 template<
class T,
class T2,
class UnaryOperation>
1328 const UList<T2>&
input,
1329 const UnaryOperation& op
1332 const label len =
input.size();
1338 const T2* in =
input.begin();
1341 for (label i = 0; i < len; ++i)
1350 template<
class T,
class InputIterator,
class UnaryOperation>
1353 InputIterator first,
1355 const UnaryOperation& op
1366 while (first != last)
1386 List<T> list(len, deflt);
1402 List<T> list(len, deflt);
1413 const UList<bool>& locations,
1418 List<T> list(len, deflt);
1429 const bitSet& locations,
1434 List<T> list(len, deflt);
1450 List<T> list(len, deflt);
1453 if (index >= 0 && index < len)
1471 List<T> list(len, deflt);
1474 if (index >= 0 && index < len)
1476 list[index] = std::move(val);
List< T > uniqueSort(const UList< T > &input)
Return sorted list with removal of duplicates.
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...
void size(const label n)
Older name for setAddressableSize.
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...
label count_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Count the number of matching entries.
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 ...
labelList findIndices(const ListType &input, const UnaryPredicate &pred, label start=0)
Linear search to find all occurences of given element.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
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.
labelList duplicateOrder(const UList< T > &input)
Return (sorted) indices corresponding to duplicate list values.
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...
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
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...
scalar distance(const vector &p1, const vector &p2)
void stableSort(UList< T > &list)
Stable sort the list.
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
label inplaceMapValue(const labelUList &oldToNew, Container &input)
Map values. Ignore negative values.
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
UList< label > labelUList
A UList of labels.
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
#define forAll(list, i)
Loop across all elements in list.
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.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
List helper to append y elements onto the end of x.
dimensionedScalar pos(const dimensionedScalar &ds)
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...
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
ListType reverseList(const ListType &input)
Reverse a list. First element becomes last element etc.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
void clear()
Clear the list, i.e. set size to zero.
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.
List helper to append y unique elements onto the end of x.
static Istream & input(Istream &is, IntRange< T > &range)
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.
List< T > create(const UList< T2 > &input, const UnaryOperation &op)
Create a List from a List of a dissimilar type, using the entire list.
Pair< label > labelPair
A pair of labels.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
void inplaceMapKey(const labelUList &oldToNew, Container &input)
Rewrite with mapped keys. Ignore elements with negative key.
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.
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values within a list.
void inplaceRotateList(ListType< DataType > &list, label n)
Inplace reversal of a list using the Reversal Block Swapping algorithm.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Exchange contents of lists - see DynamicList::swap().
label find_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
static Ostream & output(Ostream &os, const IntRange< T > &range)
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...
List< label > labelList
A List of labels.
void setValue(UList< T > &list, const labelUList &locations, const T &val)
Set various locations of the list with a specified value.
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
void inplaceReverseList(ListType &input)
Inplace reversal of a list using Swap.
A list compare binary predicate for normal sort.