35template<
class IntListType>
39 const IntListType& input
42 const label len = input.size();
44 IntListType output(len);
47 for (label i=0; i < len; ++i)
51 output[i] = oldToNew[input[i]];
59template<
class IntListType>
66 const label len = input.size();
68 for (label i=0; i < len; ++i)
72 input[i] = oldToNew[input[i]];
78template<
class ListType>
82 const ListType& input,
86 const label len = input.size();
92 for (label i=0; i < len; ++i)
94 const label newIdx = oldToNew[i];
100 output[newIdx] = input[i];
109 output[i] = input[i];
115 output.resize(maxIdx+1);
122template<
class ListType>
126 ListType& inputOutput,
136 const ListType& input = inputOutput;
137 const label len = input.
size();
139 ListType output(len);
143 for (label i=0; i < len; ++i)
145 const label newIdx = oldToNew[i];
151 output[newIdx] = input[i];
160 output[i] = input[i];
166 output.resize(maxIdx+1);
169 inputOutput.transfer(output);
173template<
unsigned W
idth>
176 const labelUList& oldToNew,
177 const PackedList<Width>& input,
181 const label len = input.size();
183 PackedList<Width> output(len);
186 for (label i=0; i < len; ++i)
188 const auto& val = input.get(i);
190 const label newIdx = oldToNew[i];
197 output.set(newIdx, val);
212 output.resize(maxIdx+1);
223template<
unsigned W
idth>
231 input =
reorder(oldToNew, input, prune);
238template<
class Container>
245 Container output(input.capacity());
247 for (
auto iter = input.begin(); iter != input.end(); ++iter)
249 const label oldIdx = iter.key();
255 output.insert(oldToNew[oldIdx], iter.val());
259 input.transfer(output);
263template<
class Container>
266 const labelUList& oldToNew,
272 for (
auto iter = input.begin(); iter != input.end(); ++iter)
274 const label oldIdx = iter.val();
280 const label newIdx = oldToNew[oldIdx];
282 if (oldIdx != newIdx)
294template<
class Container>
297 const Map<label>& mapper,
308 for (
auto iter = input.begin(); iter != input.end(); ++iter)
310 label& value = iter.val();
312 auto mapIter = mapper.find(value);
313 if (mapIter.found() && value != *mapIter)
327 const UList<T>& input
347template<
class T,
class ListComparePredicate>
352 const ListComparePredicate& comp
355 if (input.
size() < 2)
363 const label last = (order.
size()-1);
365 for (label i = 0; i < last; ++i)
367 if (input[order[i]] == input[order[i+1]])
369 order[count] = order[i];
380 const UList<T>& input
384 uniqueOrder(input, order,
typename UList<T>::less(input));
400template<
class T,
class ListComparePredicate>
405 const ListComparePredicate& comp
410 if (order.
size() > 1)
412 const label last = (order.
size()-1);
414 for (label i = 0; i < last; ++i)
416 if (input[order[i]] != input[order[i+1]])
418 order[count++] = order[i];
421 order[count++] = order[last];
430 List<T> output(input);
432 const label len = output.size();
439 for (label i = 1; i < len; ++i)
441 if (output[count] != output[i])
443 output[++count] = output[i];
447 output.resize(count+1);
454template<
class ListType>
465template<
class ListType,
class ListComparePredicate>
469 const ListComparePredicate& comp
475 const label len = order.
size();
477 ListType output(len);
480 for (label i=0; i < len; ++i)
482 output[i] = std::move(input[order[i]]);
485 input.transfer(output);
489template<
class BoolListType,
class T>
492 const BoolListType& select,
493 const UList<T>& input,
499 const label len = input.size();
505 for (label i=0; i < len; ++i)
507 if (select[i] ? !invert : invert)
509 output[count] = input[i];
514 output.resize(count);
523 const bitSet& select,
524 const UList<T>& input,
528 const label len = input.size();
536 output.resize(
select.count());
538 for (
const label i : select)
542 output[
count] = input[i];
549 output.resize(outlen);
551 for (label i=0; i < len; ++i)
555 output[
count] = input[i];
557 if (count >= outlen)
break;
562 output.resize(count);
568template<
class BoolListType,
class ListType>
571 const BoolListType& select,
578 const label len = input.size();
582 for (label i=0; i < len; ++i)
588 input[count] = std::move(input[i]);
598template<
class ListType>
612 const label len = input.size();
614 for (
const label i : select)
620 input[count] = std::move(input[i]);
629 const label outlen = (select.
size() - select.count());
631 const label len =
min(input.size(), select.
size());
633 for (label i=0; i < len; ++i)
639 input[count] = std::move(input[i]);
642 if (count >= outlen)
break;
651template<
class T,
class UnaryPredicate>
654 const UList<T>& input,
655 const UnaryPredicate& pred,
659 const label len = input.size();
664 for (label i=0; i < len; ++i)
666 if (pred(input[i]) ? !invert : invert)
668 output[count] = input[i];
673 output.resize(count);
679template<
class ListType,
class UnaryPredicate>
683 const UnaryPredicate& pred,
687 const label len = input.size();
690 for (label i=0; i < len; ++i)
696 input[count] = std::move(input[i]);
705template<
class InputIntListType,
class OutputIntListType>
716 for (
const InputIntListType& sublist : input)
720 sizes[sublist[idx]]++;
728 output[outi].
resize(sizes[outi]);
735 const InputIntListType& sublist = input[listi];
739 const label outi = sublist[idx];
741 output[outi][sizes[outi]++] = listi;
747template<
class ListType>
750 const ListType& input,
751 typename ListType::const_reference val,
755 const label len = input.
size();
762 for (label i = start; i < len; ++i)
766 if (!count) start = i;
777 const label total =
count;
779 for (label i = start; i < len; ++i)
784 if (++count == total)
796template<
class ListType>
799 const ListType& input,
803 const label len = input.size();
805 if (start < 0 || start >= len)
810 for (label i = start+1; i < len; ++i)
812 if (input[i] < input[start])
822template<
class ListType>
825 const ListType& input,
829 const label len = input.size();
831 if (start < 0 || start >= len)
836 for (label i = start+1; i < len; ++i)
838 if (input[start] < input[i])
848template<
class ListType>
851 const ListType& input,
855 const label len = input.
size();
857 if (start < 0 || start >= len)
862 label minIdx = start;
863 label maxIdx = start;
865 for (label i = start+1; i < len; ++i)
867 if (input[i] < input[minIdx])
871 if (input[maxIdx] < input[i])
881template<
class ListType>
884 const ListType& input,
885 typename ListType::const_reference val,
890 label high = input.size() - 1;
892 if (start < 0 || start >= input.size())
899 const label mid = (low + high)/2;
901 if (val < input[mid])
905 else if (input[mid] < val)
919template<
class ListType,
class T,
class ComparePredicate>
922 const ListType& input,
925 const ComparePredicate& comp
929 label high = input.size() - 1;
931 if (start < 0 || start >= input.size())
936 while ((high - low) > 1)
938 const label mid = (low + high)/2;
940 if (comp(input[mid], val))
950 if (comp(input[high], val))
954 else if (comp(input[low], val))
965template<
class ListType,
class T>
968 const ListType& input,
983template<
class ListType>
986 const label len = input.size();
987 const label last = (len - 1);
989 ListType output(len);
992 for (label i=0; i < len; ++i)
994 output[i] = input[last - i];
1001template<
class ListType>
1004 const label len = input.size();
1005 const label last = (len - 1);
1006 const label n2 = len >> 1;
1008 for (label i=0; i<n2; ++i)
1015template<
class ListType>
1018 const label len = input.size();
1020 ListType output(len);
1023 for (label i=0; i<len; ++i)
1025 label index = (i -
n) % len;
1032 output[i] = input[index];
1039template<
template<
typename>
class ListType,
class DataType>
1042 const label len = input.size();
1044 n = (len -
n) % len;
1072 label len =
x.size();
1075 x.resize(len +
y.size());
1076 for (
const T& val :
y)
1100 for (
const T& val :
y)
1116template<
class ListType,
class UnaryPredicate>
1119 const ListType& input,
1120 const UnaryPredicate& pred,
1126 const label len = input.size();
1130 for (label i = start; i < len; ++i)
1143template<
class ListType,
class UnaryPredicate>
1146 const ListType& input,
1147 const UnaryPredicate& pred,
1151 const label len = input.size();
1155 for (label i = start; i < len; ++i)
1168template<
class ListType,
class UnaryPredicate>
1171 const ListType& input,
1172 const UnaryPredicate& pred,
1176 return (ListOps::find_if(input, pred, start) >= 0);
1180template<
class ListType,
class UnaryPredicate>
1183 const ListType& input,
1184 const UnaryPredicate& pred,
1188 const label len = input.
size();
1195 for (label i = start; i < len; ++i)
1199 if (!count) start = i;
1210 const label total =
count;
1212 for (label i = start; i < len; ++i)
1217 if (++count == total)
1237 const label len = list.
size();
1239 for (
const label index : locations)
1242 if (index >= 0 && index < len)
1258 const label len = list.
size();
1260 for (
const label index : locations)
1263 if (index >= 0 && index < len)
1279 const label len = list.
size();
1280 const label count = locations.
size();
1281 const label end =
min(count, len);
1284 for (label index = 0; index < end; ++index)
1286 if (locations[index])
1302 const label len = list.
size();
1316template<
class T,
class T2,
class UnaryOperation>
1320 const UnaryOperation& op
1323 const label len = input.
size();
1332 for (label i = 0; i < len; ++i)
1342template<
class T,
class InputIterator,
class UnaryOperation>
1345 InputIterator first,
1347 const UnaryOperation& op
1350 const label len = std::distance(first, last);
1352 List<T> output(len);
1356 T* out = output.begin();
1358 while (first != last)
1374 const labelUList& locations,
1379 List<T> list(len, deflt);
1380 ListOps::setValue(list, locations, val);
1390 const labelHashSet& locations,
1395 List<T> list(len, deflt);
1396 ListOps::setValue(list, locations, val);
1406 const UList<bool>& locations,
1411 List<T> list(len, deflt);
1412 ListOps::setValue(list, locations, val);
1422 const bitSet& locations,
1427 List<T> list(len, deflt);
1428 ListOps::setValue(list, locations, val);
1443 List<T> list(len, deflt);
1446 if (index >= 0 && index < len)
1464 List<T> list(len, deflt);
1467 if (index >= 0 && index < len)
1469 list[index] = std::move(val);
Macros for accessing List elements.
#define List_ACCESS(type, f, fp)
#define List_CONST_ACCESS(type, f, fp)
Various functions to operate on Lists.
static constexpr label size() noexcept
Return the number of elements in the FixedList.
void resize(const label len)
Adjust allocated size of list.
void clear()
Clear the list, i.e. set size to zero.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
A List obtained as a section of another List.
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.
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
List< bool > select(const label n, const labelUList &locations)
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.
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.
List< T > createWithValue(const label len, const labelUList &locations, const T &val, const T &deflt=T())
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 (not the indices) of a list.
List< label > labelList
A List of labels.
label findMin(const ListType &input, label start=0)
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.
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)
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)
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
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)
label findMax(const ListType &input, label start=0)
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
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.
A list compare binary predicate for normal sort.