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 ListType>
78 const ListType&
input,
82 const label len =
input.size();
88 for (label i=0; i < len; ++i)
90 const label newIdx = oldToNew[i];
118 template<
class ListType>
122 ListType& inputOutput,
132 const ListType&
input = inputOutput;
133 const label len =
input.size();
139 for (label i=0; i < len; ++i)
141 const label newIdx = oldToNew[i];
165 inputOutput.transfer(
output);
169 template<
unsigned W
idth>
173 const PackedList<Width>&
input,
177 const label len =
input.size();
179 PackedList<Width>
output(len);
182 for (label i=0; i < len; ++i)
184 const auto& val =
input.get(i);
186 const label newIdx = oldToNew[i];
219 template<
unsigned W
idth>
223 PackedList<Width>&
input,
234 template<
class Container>
243 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
245 const label oldIdx = iter.key();
251 output.insert(oldToNew[oldIdx], iter.val());
259 template<
class Container>
268 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
270 const label oldIdx = iter.val();
276 const label newIdx = oldToNew[oldIdx];
278 if (oldIdx != newIdx)
290 template<
class Container>
293 const Map<label>& mapper,
304 for (
auto iter =
input.begin(); iter !=
input.end(); ++iter)
306 label& value = iter.val();
308 auto mapIter = mapper.find(value);
309 if (mapIter.good() && value != mapIter.val())
311 value = mapIter.val();
323 const UList<T>&
input 335 const UList<T>&
input,
343 template<
class T,
class ListComparePredicate>
346 const UList<T>&
input,
348 const ListComparePredicate& comp
351 if (
input.size() < 2)
359 const label last = (order.size()-1);
361 for (label i = 0; i < last; ++i)
365 order[
count] = order[i];
376 const UList<T>&
input 388 const UList<T>&
input,
396 template<
class T,
class ListComparePredicate>
399 const UList<T>&
input,
401 const ListComparePredicate& comp
406 if (order.size() > 1)
408 const label last = (order.size()-1);
410 for (label i = 0; i < last; ++i)
414 order[
count++] = order[i];
417 order[
count++] = order[last];
428 const label len =
output.size();
435 for (label i = 1; i < len; ++i)
450 template<
class ListType>
461 template<
class ListType,
class ListComparePredicate>
465 const ListComparePredicate& comp
471 const label len = order.size();
476 for (label i=0; i < len; ++i)
485 template<
class BoolListType,
class T>
488 const BoolListType&
select,
489 const UList<T>&
input,
495 const label len =
input.size();
501 for (label i=0; i < len; ++i)
520 const UList<T>&
input,
524 const label len =
input.size();
534 for (
const label i :
select)
547 for (label i=0; i < len; ++i)
553 if (
count >= outlen)
break;
564 template<
class BoolListType,
class ListType>
567 const BoolListType&
select,
574 const label len =
input.size();
578 for (label i=0; i < len; ++i)
594 template<
class ListType>
608 const label len =
input.size();
610 for (
const label i :
select)
629 for (label i=0; i < len; ++i)
638 if (
count >= outlen)
break;
647 template<
class T,
class UnaryPredicate>
650 const UList<T>&
input,
651 const UnaryPredicate& pred,
655 const label len =
input.size();
660 for (label i=0; i < len; ++i)
675 template<
class ListType,
class UnaryPredicate>
679 const UnaryPredicate& pred,
683 const label len =
input.size();
686 for (label i=0; i < len; ++i)
701 template<
class InputIntListType,
class OutputIntListType>
705 const UList<InputIntListType>&
input,
706 List<OutputIntListType>&
output 712 for (
const InputIntListType& sublist :
input)
716 sizes[sublist[idx]]++;
724 output[outi].resize(sizes[outi]);
731 const InputIntListType& sublist =
input[listi];
735 const label outi = sublist[idx];
737 output[outi][sizes[outi]++] = listi;
743 template<
class ListType>
746 const ListType&
input,
747 typename ListType::const_reference val,
751 const label len =
input.size();
758 for (label i = start; i < len; ++i)
762 if (!
count) start = i;
773 const label total =
count;
775 for (label i = start; i < len; ++i)
780 if (++
count == total)
792 template<
class ListType>
795 const ListType&
input,
799 const label len =
input.size();
801 if (start < 0 || start >= len)
806 for (label i = start+1; i < len; ++i)
818 template<
class ListType>
821 const ListType&
input,
825 const label len =
input.size();
827 if (start < 0 || start >= len)
832 for (label i = start+1; i < len; ++i)
844 template<
class ListType>
847 const ListType&
input,
851 const label len =
input.size();
853 if (start < 0 || start >= len)
858 label minIdx = start;
859 label maxIdx = start;
861 for (label i = start+1; i < len; ++i)
877 template<
class ListType>
880 const ListType&
input,
881 typename ListType::const_reference val,
886 label high =
input.size() - 1;
888 if (start < 0 || start >=
input.size())
895 const label mid = (low + high)/2;
897 if (val <
input[mid])
901 else if (
input[mid] < val)
915 template<
class ListType,
class T,
class ComparePredicate>
918 const ListType&
input,
921 const ComparePredicate& comp
925 label high =
input.size() - 1;
927 if (start < 0 || start >=
input.size())
932 while ((high - low) > 1)
934 const label mid = (low + high)/2;
936 if (comp(
input[mid], val))
946 if (comp(
input[high], val))
950 else if (comp(
input[low], val))
961 template<
class ListType,
class T>
964 const ListType&
input,
979 template<
class ListType>
982 const label len =
input.size();
983 const label last = (len - 1);
988 for (label i=0; i < len; ++i)
997 template<
class ListType>
1000 const label len =
input.size();
1001 const label last = (len - 1);
1002 const label n2 = len >> 1;
1004 for (label i=0; i<n2; ++i)
1011 template<
class ListType>
1014 const label len =
input.size();
1019 for (label i=0; i<len; ++i)
1021 label index = (i -
n) % len;
1035 template<
template<
typename>
class ListType,
class DataType>
1038 const label len =
input.size();
1040 n = (len -
n) % len;
1047 SubList<DataType> firstHalf(
input,
n, 0);
1048 SubList<DataType> secondHalf(
input, len -
n,
n);
1068 label len =
x.size();
1071 x.resize(len +
y.size());
1072 for (
const T& val :
y)
1096 for (
const T& val :
y)
1099 if (!
x.contains(val))
1113 template<
class ListType,
class UnaryPredicate>
1116 const ListType&
input,
1117 const UnaryPredicate& pred,
1123 const label len =
input.size();
1127 for (label i = start; i < len; ++i)
1140 template<
class ListType,
class UnaryPredicate>
1143 const ListType&
input,
1144 const UnaryPredicate& pred,
1148 const label len =
input.size();
1152 for (label i = start; i < len; ++i)
1165 template<
class ListType,
class UnaryPredicate>
1168 const ListType&
input,
1169 const UnaryPredicate& pred,
1177 template<
class ListType,
class UnaryPredicate>
1180 const ListType&
input,
1181 const UnaryPredicate& pred,
1185 const label len =
input.size();
1192 for (label i = start; i < len; ++i)
1196 if (!
count) start = i;
1207 const label total =
count;
1209 for (label i = start; i < len; ++i)
1214 if (++
count == total)
1234 const label len = list.
size();
1236 for (
const label index : locations)
1239 if (index >= 0 && index < len)
1255 const label len = list.size();
1257 for (
const label index : locations)
1260 if (index >= 0 && index < len)
1272 const UList<bool>& locations,
1276 const label len = list.size();
1277 const label
count = locations.size();
1281 for (label index = 0; index <
end; ++index)
1283 if (locations[index])
1295 const bitSet& locations,
1299 const label len = list.size();
1303 label
pos = locations.find_first();
1305 pos = locations.find_next(
pos)
1313 template<
class T,
class T2,
class UnaryOperation>
1316 const UList<T2>&
input,
1317 const UnaryOperation& op
1320 const label len =
input.size();
1326 const T2* in =
input.begin();
1329 for (label i = 0; i < len; ++i)
1338 template<
class T,
class InputIterator,
class UnaryOperation>
1341 InputIterator first,
1343 const UnaryOperation& op
1354 while (first != last)
1374 List<T> list(len, deflt);
1390 List<T> list(len, deflt);
1401 const UList<bool>& locations,
1406 List<T> list(len, deflt);
1417 const bitSet& locations,
1422 List<T> list(len, deflt);
1438 List<T> list(len, deflt);
1441 if (index >= 0 && index < len)
1459 List<T> list(len, deflt);
1462 if (index >= 0 && index < len)
1464 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 (not the indices) of 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 (not the indices) of 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)
label find_if(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
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.
static constexpr const zero Zero
Global zero (0)