Go to the documentation of this file.
35 template<
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]];
59 template<
class IntListType>
66 const label len = input.size();
68 for (label i=0; i < len; ++i)
72 input[i] = oldToNew[input[i]];
78 template<
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);
122 template<
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);
173 template<
unsigned W
idth>
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);
223 template<
unsigned W
idth>
231 input =
reorder(oldToNew, input, prune);
238 template<
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());
263 template<
class Container>
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)
294 template<
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
347 template<
class T,
class ListComparePredicate>
352 const ListComparePredicate& comp
355 const label len = input.
size();
358 if (order.size() != len)
374 const UList<T>& input
394 template<
class T,
class ListComparePredicate>
399 const ListComparePredicate& comp
402 if (input.
size() < 2)
410 const label last = (order.size()-1);
412 for (label i = 0; i < last; ++i)
414 if (input[order[i]] == input[order[i+1]])
416 order[
count] = order[i];
427 const UList<T>& input
447 template<
class T,
class ListComparePredicate>
452 const ListComparePredicate& comp
457 if (order.size() > 1)
459 const label last = (order.size()-1);
461 for (label i = 0; i < last; ++i)
463 if (input[order[i]] != input[order[i+1]])
465 order[
count++] = order[i];
468 order[
count++] = order[last];
474 template<
class ListType>
485 template<
class ListType,
class ListComparePredicate>
489 const ListComparePredicate& comp
495 const label len = order.size();
497 ListType output(len);
500 for (label i=0; i < len; ++i)
502 output[i] = std::move(input[order[i]]);
505 input.transfer(output);
509 template<
class BoolListType,
class T>
512 const BoolListType& select,
513 const UList<T>& input,
519 const label len = input.size();
525 for (label i=0; i < len; ++i)
529 output[
count] = input[i];
543 const bitSet& select,
544 const UList<T>& input,
548 const label len = input.size();
556 output.resize(select.count());
558 for (
const label i : select)
562 output[
count] = input[i];
568 const label outlen = (select.size() - select.count());
569 output.resize(outlen);
571 for (label i=0; i < len; ++i)
575 output[
count] = input[i];
577 if (
count >= outlen)
break;
582 output.resize(
count);
588 template<
class BoolListType,
class ListType>
591 const BoolListType& select,
598 const label len = input.size();
602 for (label i=0; i < len; ++i)
608 input[
count] = std::move(input[i]);
618 template<
class ListType>
632 const label len = input.size();
634 for (
const label i : select)
640 input[
count] = std::move(input[i]);
649 const label outlen = (select.
size() - select.
count());
651 const label len =
min(input.size(), select.
size());
653 for (label i=0; i < len; ++i)
659 input[
count] = std::move(input[i]);
662 if (
count >= outlen)
break;
671 template<
class T,
class UnaryPredicate>
674 const UList<T>& input,
675 const UnaryPredicate& pred,
679 const label len = input.size();
684 for (label i=0; i < len; ++i)
688 output[
count] = input[i];
693 output.resize(
count);
699 template<
class ListType,
class UnaryPredicate>
703 const UnaryPredicate& pred,
707 const label len = input.size();
710 for (label i=0; i < len; ++i)
716 input[
count] = std::move(input[i]);
725 template<
class InputIntListType,
class OutputIntListType>
736 for (
const InputIntListType& sublist : input)
740 sizes[sublist[idx]]++;
748 output[outi].
resize(sizes[outi]);
755 const InputIntListType& sublist = input[listi];
759 const label outi = sublist[idx];
761 output[outi][sizes[outi]++] = listi;
767 template<
class ListType>
770 const ListType& input,
771 typename ListType::const_reference val,
775 const label len = input.size();
782 for (label i = start; i < len; ++i)
786 if (!
count) start = i;
797 const label total =
count;
799 for (label i = start; i < len; ++i)
804 if (++
count == total)
816 template<
class ListType>
819 const ListType& input,
823 const label len = input.size();
825 if (start < 0 || start >= len)
830 for (label i = start+1; i < len; ++i)
832 if (input[i] < input[start])
842 template<
class ListType>
845 const ListType& input,
849 const label len = input.size();
851 if (start < 0 || start >= len)
856 for (label i = start+1; i < len; ++i)
858 if (input[start] < input[i])
868 template<
class ListType>
871 const ListType& input,
875 const label len = input.size();
877 if (start < 0 || start >= len)
882 label minIdx = start;
883 label maxIdx = start;
885 for (label i = start+1; i < len; ++i)
887 if (input[i] < input[minIdx])
891 if (input[maxIdx] < input[i])
901 template<
class ListType>
904 const ListType& input,
905 typename ListType::const_reference val,
910 label high = input.size() - 1;
912 if (start < 0 || start >= input.size())
919 const label mid = (low + high)/2;
921 if (val < input[mid])
925 else if (input[mid] < val)
939 template<
class ListType,
class T,
class ComparePredicate>
942 const ListType& input,
945 const ComparePredicate& comp
949 label high = input.size() - 1;
951 if (start < 0 || start >= input.size())
956 while ((high - low) > 1)
958 const label mid = (low + high)/2;
960 if (comp(input[mid], val))
970 if (comp(input[high], val))
974 else if (comp(input[low], val))
985 template<
class ListType,
class T>
988 const ListType& input,
1003 template<
class ListType>
1006 const label len = input.size();
1007 const label last = (len - 1);
1009 ListType output(len);
1012 for (label i=0; i < len; ++i)
1014 output[i] = input[last - i];
1021 template<
class ListType>
1024 const label len = input.size();
1025 const label last = (len - 1);
1026 const label n2 = len >> 1;
1028 for (label i=0; i<n2; ++i)
1035 template<
class ListType>
1038 const label len = input.size();
1040 ListType output(len);
1043 for (label i=0; i<len; ++i)
1045 label index = (i -
n) % len;
1052 output[i] = input[index];
1059 template<
template<
typename>
class ListType,
class DataType>
1062 const label len = input.size();
1064 n = (len -
n) % len;
1092 label len =
x.size();
1095 x.resize(len +
y.size());
1096 for (
const T& val :
y)
1120 for (
const T& val :
y)
1136 template<
class ListType,
class UnaryPredicate>
1139 const ListType& input,
1140 const UnaryPredicate& pred,
1144 const label len = input.size();
1148 for (label i = start; i < len; ++i)
1161 template<
class ListType,
class UnaryPredicate>
1164 const ListType& input,
1165 const UnaryPredicate& pred,
1181 const label len = list.
size();
1183 for (
const label index : locations)
1186 if (index >= 0 && index < len)
1202 const label len = list.
size();
1204 for (
const label index : locations)
1207 if (index >= 0 && index < len)
1223 const label len = list.
size();
1228 for (label index = 0; index <
end; ++index)
1230 if (locations[index])
1246 const label len = list.
size();
1260 template<
class T,
class T2,
class UnaryOperation>
1264 const UnaryOperation& op
1267 const label len = input.
size();
1276 for (label i = 0; i < len; ++i)
1286 template<
class T,
class InputIterator,
class UnaryOperation>
1289 InputIterator first,
1291 const UnaryOperation& op
1296 List<T> output(len);
1300 T* out = output.begin();
1302 while (first != last)
1323 List<T> list(len, deflt);
1339 List<T> list(len, deflt);
1350 const UList<bool>& locations,
1355 List<T> list(len, deflt);
1366 const bitSet& locations,
1371 List<T> list(len, deflt);
1387 List<T> list(len, deflt);
1390 if (index >= 0 && index < len)
1408 List<T> list(len, deflt);
1411 if (index >= 0 && index < len)
1413 list[index] = std::move(val);
List< label > labelList
A List of labels.
label find_first() const
Locate the first bit that is set.
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
void inplaceReverseList(ListType &input)
Inplace reversal of a list using Swap.
labelList uniqueOrder(const UList< T > &input)
Return (sorted) indices corresponding to unique list values.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
static constexpr const zero Zero
Global zero (0)
static bool less(const vector &x, const vector &y)
To compare normals.
A List obtained as a section of another List.
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 > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
void inplaceRotateList(ListType< DataType > &list, label n)
Inplace reversal of a list using the Reversal Block Swapping algorithm.
void inplaceUniqueSort(ListType &input)
Inplace sorting and removal of duplicates.
List< T > createWithValue(const label len, const labelUList &locations, const T &val, const T &deflt=T())
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
unsigned int count(const bool on=true) const
Count number of bits set.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
#define forAll(list, i)
Loop across all elements in list.
void stableSort(UList< T > &a)
void invertManyToMany(const label len, const UList< InputIntListType > &input, List< OutputIntListType > &output)
Invert many-to-many.
Pair< label > labelPair
A pair of labels.
labelPair findMinMax(const ListType &input, label start=0)
void inplaceMapKey(const labelUList &oldToNew, Container &input)
Rewrite with mapped keys. Ignore elements with negative key.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
void transfer(List< T > &list)
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
A list compare binary predicate for normal sort.
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
label inplaceMapValue(const labelUList &oldToNew, Container &input)
Map values. Ignore negative values.
void resize(const label newSize)
Adjust allocated size of list.
labelList duplicateOrder(const UList< T > &input)
Return (sorted) indices corresponding to duplicate list values.
label find_next(label pos) const
Locate the next bit set, starting one beyond the specified position.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
ListType rotateList(const ListType &list, const label n)
Rotate a list by n places.
List helper to append y unique elements onto the end of x.
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
scalar distance(const vector &p1, const vector &p2)
List helper to append y elements onto the end of x.
ListType reverseList(const ListType &input)
Reverse a list. First element becomes last element etc.
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
#define List_CONST_ACCESS(type, f, fp)
void setValue(UList< T > &list, const labelUList &locations, const T &val)
Set various locations of the list with a specified value.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
label findMax(const ListType &input, label start=0)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
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.
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
void clear()
Clear the list, i.e. set size to zero.
bool found(const ListType &input, const UnaryPredicate &pred, const label start=0)
True if there is a value in the list that satisfies the predicate.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
Various functions to operate on Lists.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
UList< label > labelUList
A UList of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
#define List_ACCESS(type, f, fp)
label findMin(const ListType &input, label start=0)
Macros for accessing List elements.
dimensionedScalar pos(const dimensionedScalar &ds)
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.